This commit is contained in:
Fredrik Burmester
2024-10-12 13:41:09 +02:00
parent bf8687a473
commit ba6322bb1f
3 changed files with 58 additions and 25 deletions

View File

@@ -152,9 +152,16 @@ export default function page() {
if (isSeeking.value === true) return;
if (isPlaybackStopped === true) return;
const { currentTime, duration } = data.nativeEvent;
const { currentTime, duration, isBuffering, isPlaying } =
data.nativeEvent;
console.log("onProgress ~", {
currentTime,
duration,
isBuffering,
isPlaying,
});
console.log("onProgress ~", currentTime);
progress.value = currentTime;
// cacheProgress.value = secondsToTicks(data.playableDuration);
@@ -297,7 +304,7 @@ export default function page() {
/>
</Pressable>
<VideoDebugInfo
{/* <VideoDebugInfo
style={{
position: "absolute",
top: 0,
@@ -310,7 +317,7 @@ export default function page() {
duration: 0,
}}
playerRef={videoRef}
/>
/> */}
<Controls
item={playSettings.item}

View File

@@ -431,36 +431,51 @@ extension VlcPlayerView: VLCMediaPlayerDelegate {
"isBuffering": currentState == .buffering,
]
switch currentState {
case .opening:
stateInfo["state"] = "Opening"
case .buffering:
stateInfo["state"] = "Buffering"
stateInfo["isBuffering"] = true
case .playing:
if player.state == .playing {
stateInfo["isPlaying"] = true
stateInfo["isBuffering"] = false
stateInfo["state"] = "Playing"
case .paused:
stateInfo["state"] = "Paused"
case .stopped:
stateInfo["state"] = "Stopped"
case .ended:
stateInfo["state"] = "Ended"
case .error:
stateInfo["state"] = "Error"
default:
stateInfo["state"] = "Unknown"
}
if currentState != self.lastReportedState {
self.lastReportedState = currentState
self.onVideoStateChange?(stateInfo)
if player.state == .buffering {
stateInfo["isBuffering"] = true
stateInfo["state"] = "Buffering"
}
if player.state == .paused {
stateInfo["isPlaying"] = false
stateInfo["state"] = "Paused"
}
// switch currentState {
// case .opening:
// stateInfo["state"] = "Opening"
// case .buffering:
// stateInfo["state"] = "Buffering"
// stateInfo["isBuffering"] = true
// case .playing:
// stateInfo["state"] = "Playing"
// case .paused:
// stateInfo["state"] = "Paused"
// case .stopped:
// stateInfo["state"] = "Stopped"
// case .ended:
// stateInfo["state"] = "Ended"
// case .error:
// stateInfo["state"] = "Error"
// default:
// stateInfo["state"] = "Unknown"
// }
self.lastReportedState = currentState
self.onVideoStateChange?(stateInfo)
}
}
func mediaPlayerTimeChanged(_ aNotification: Notification) {
DispatchQueue.main.async { [weak self] in
self?.updateVideoProgress()
self?.updatePlayerState()
}
}
@@ -472,11 +487,20 @@ extension VlcPlayerView: VLCMediaPlayerDelegate {
let durationMs = player.media?.length.intValue ?? 0
if currentTimeMs >= 0 && currentTimeMs < durationMs {
let isPlaying = player.isPlaying
let isBuffering = player.state == .buffering
self.onVideoProgress?([
"target": self.reactTag ?? NSNull(),
"currentTime": currentTimeMs,
"duration": durationMs,
"isPlaying": isPlaying,
"isBuffering": isBuffering,
])
// Debug log
print(
"VLC Player State: \(player.state.description), isPlaying: \(isPlaying), isBuffering: \(isBuffering)"
)
}
}
}

View File

@@ -21,6 +21,8 @@ export type ProgressUpdatePayload = {
nativeEvent: {
currentTime: number;
duration: number;
isPlaying: boolean;
isBuffering: boolean;
};
};