mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
fix: play states working
This commit is contained in:
@@ -155,12 +155,12 @@ export default function page() {
|
|||||||
const { currentTime, duration, isBuffering, isPlaying } =
|
const { currentTime, duration, isBuffering, isPlaying } =
|
||||||
data.nativeEvent;
|
data.nativeEvent;
|
||||||
|
|
||||||
console.log("onProgress ~", {
|
// console.log("onProgress ~", {
|
||||||
currentTime,
|
// currentTime,
|
||||||
duration,
|
// duration,
|
||||||
isBuffering,
|
// isBuffering,
|
||||||
isPlaying,
|
// isPlaying,
|
||||||
});
|
// });
|
||||||
|
|
||||||
progress.value = currentTime;
|
progress.value = currentTime;
|
||||||
|
|
||||||
|
|||||||
@@ -4,31 +4,68 @@ import {
|
|||||||
Subscription,
|
Subscription,
|
||||||
} from "expo-modules-core";
|
} from "expo-modules-core";
|
||||||
|
|
||||||
// Import the native module. On web, it will be resolved to VlcPlayer.web.ts
|
|
||||||
// and on native platforms to VlcPlayer.ts
|
|
||||||
import VlcPlayerModule from "./src/VlcPlayerModule";
|
import VlcPlayerModule from "./src/VlcPlayerModule";
|
||||||
import VlcPlayerView from "./src/VlcPlayerView";
|
import VlcPlayerView from "./src/VlcPlayerView";
|
||||||
import { ChangeEventPayload, VlcPlayerViewProps } from "./src/VlcPlayer.types";
|
import {
|
||||||
|
PlaybackStatePayload,
|
||||||
// Get the native constant value.
|
ProgressUpdatePayload,
|
||||||
export const PI = VlcPlayerModule.PI;
|
VideoLoadStartPayload,
|
||||||
|
VideoStateChangePayload,
|
||||||
export function hello(): string {
|
VideoProgressPayload,
|
||||||
return VlcPlayerModule.hello();
|
VlcPlayerSource,
|
||||||
}
|
TrackInfo,
|
||||||
|
ChapterInfo,
|
||||||
export async function setValueAsync(value: string) {
|
VlcPlayerViewProps,
|
||||||
return await VlcPlayerModule.setValueAsync(value);
|
VlcPlayerViewRef,
|
||||||
}
|
} from "./src/VlcPlayer.types";
|
||||||
|
|
||||||
const emitter = new EventEmitter(
|
const emitter = new EventEmitter(
|
||||||
VlcPlayerModule ?? NativeModulesProxy.VlcPlayer
|
VlcPlayerModule ?? NativeModulesProxy.VlcPlayer
|
||||||
);
|
);
|
||||||
|
|
||||||
export function addChangeListener(
|
export function addPlaybackStateListener(
|
||||||
listener: (event: ChangeEventPayload) => void
|
listener: (event: PlaybackStatePayload) => void
|
||||||
): Subscription {
|
): Subscription {
|
||||||
return emitter.addListener<ChangeEventPayload>("onChange", listener);
|
return emitter.addListener<PlaybackStatePayload>(
|
||||||
|
"onPlaybackStateChanged",
|
||||||
|
listener
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { VlcPlayerView, VlcPlayerViewProps, ChangeEventPayload };
|
export function addVideoLoadStartListener(
|
||||||
|
listener: (event: VideoLoadStartPayload) => void
|
||||||
|
): Subscription {
|
||||||
|
return emitter.addListener<VideoLoadStartPayload>(
|
||||||
|
"onVideoLoadStart",
|
||||||
|
listener
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addVideoStateChangeListener(
|
||||||
|
listener: (event: VideoStateChangePayload) => void
|
||||||
|
): Subscription {
|
||||||
|
return emitter.addListener<VideoStateChangePayload>(
|
||||||
|
"onVideoStateChange",
|
||||||
|
listener
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addVideoProgressListener(
|
||||||
|
listener: (event: VideoProgressPayload) => void
|
||||||
|
): Subscription {
|
||||||
|
return emitter.addListener<VideoProgressPayload>("onVideoProgress", listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
VlcPlayerView,
|
||||||
|
VlcPlayerViewProps,
|
||||||
|
VlcPlayerViewRef,
|
||||||
|
PlaybackStatePayload,
|
||||||
|
ProgressUpdatePayload,
|
||||||
|
VideoLoadStartPayload,
|
||||||
|
VideoStateChangePayload,
|
||||||
|
VideoProgressPayload,
|
||||||
|
VlcPlayerSource,
|
||||||
|
TrackInfo,
|
||||||
|
ChapterInfo,
|
||||||
|
};
|
||||||
|
|||||||
@@ -421,20 +421,20 @@ extension VlcPlayerView: VLCMediaPlayerDelegate {
|
|||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self, let player = self.mediaPlayer else { return }
|
guard let self = self, let player = self.mediaPlayer else { return }
|
||||||
let currentState = player.state
|
let currentState = player.state
|
||||||
print("VLC Player State Changed: \(currentState.description)")
|
|
||||||
|
|
||||||
var stateInfo: [String: Any] = [
|
var stateInfo: [String: Any] = [
|
||||||
"target": self.reactTag ?? NSNull(),
|
"target": self.reactTag ?? NSNull(),
|
||||||
"currentTime": player.time.intValue,
|
"currentTime": player.time.intValue,
|
||||||
"duration": player.media?.length.intValue ?? 0,
|
"duration": player.media?.length.intValue ?? 0,
|
||||||
"isPlaying": currentState == .playing,
|
|
||||||
"isBuffering": currentState == .buffering,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if player.state == .playing {
|
if player.isPlaying {
|
||||||
stateInfo["isPlaying"] = true
|
stateInfo["isPlaying"] = true
|
||||||
stateInfo["isBuffering"] = false
|
stateInfo["isBuffering"] = false
|
||||||
stateInfo["state"] = "Playing"
|
stateInfo["state"] = "Playing"
|
||||||
|
} else {
|
||||||
|
stateInfo["isPlaying"] = false
|
||||||
|
stateInfo["state"] = "Paused"
|
||||||
}
|
}
|
||||||
|
|
||||||
if player.state == .buffering {
|
if player.state == .buffering {
|
||||||
@@ -442,10 +442,8 @@ extension VlcPlayerView: VLCMediaPlayerDelegate {
|
|||||||
stateInfo["state"] = "Buffering"
|
stateInfo["state"] = "Buffering"
|
||||||
}
|
}
|
||||||
|
|
||||||
if player.state == .paused {
|
print("VLC Player State Changed: \(currentState.description)")
|
||||||
stateInfo["isPlaying"] = false
|
print("VLC Player State Changed: \(player.isPlaying)")
|
||||||
stateInfo["state"] = "Paused"
|
|
||||||
}
|
|
||||||
|
|
||||||
// switch currentState {
|
// switch currentState {
|
||||||
// case .opening:
|
// case .opening:
|
||||||
@@ -475,7 +473,6 @@ extension VlcPlayerView: VLCMediaPlayerDelegate {
|
|||||||
func mediaPlayerTimeChanged(_ aNotification: Notification) {
|
func mediaPlayerTimeChanged(_ aNotification: Notification) {
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
self?.updateVideoProgress()
|
self?.updateVideoProgress()
|
||||||
self?.updatePlayerState()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,20 +484,10 @@ extension VlcPlayerView: VLCMediaPlayerDelegate {
|
|||||||
let durationMs = player.media?.length.intValue ?? 0
|
let durationMs = player.media?.length.intValue ?? 0
|
||||||
|
|
||||||
if currentTimeMs >= 0 && currentTimeMs < durationMs {
|
if currentTimeMs >= 0 && currentTimeMs < durationMs {
|
||||||
let isPlaying = player.isPlaying
|
|
||||||
let isBuffering = player.state == .buffering
|
|
||||||
|
|
||||||
self.onVideoProgress?([
|
self.onVideoProgress?([
|
||||||
"currentTime": currentTimeMs,
|
"currentTime": currentTimeMs,
|
||||||
"duration": durationMs,
|
"duration": durationMs,
|
||||||
"isPlaying": isPlaying,
|
|
||||||
"isBuffering": isBuffering,
|
|
||||||
])
|
])
|
||||||
|
|
||||||
// Debug log
|
|
||||||
print(
|
|
||||||
"VLC Player State: \(player.state.description), isPlaying: \(isPlaying), isBuffering: \(isBuffering)"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user