This commit is contained in:
Alex Kim
2026-01-10 02:31:21 +11:00
parent fd2d420320
commit d1fdea76e8
8 changed files with 270 additions and 952 deletions

View File

@@ -148,12 +148,14 @@ class MpvPlayerView: ExpoView {
func play() {
intendedPlayState = true
renderer?.play()
pipController?.setPlaybackRate(1.0)
pipController?.updatePlaybackState()
}
func pause() {
intendedPlayState = false
renderer?.pausePlayback()
pipController?.setPlaybackRate(0.0)
pipController?.updatePlaybackState()
}
@@ -283,9 +285,9 @@ extension MpvPlayerView: MPVSoftwareRendererDelegate {
DispatchQueue.main.async { [weak self] in
guard let self else { return }
// Only update PiP state when PiP is active
// Update PiP current time for progress bar
if self.pipController?.isPictureInPictureActive == true {
self.pipController?.updatePlaybackState()
self.pipController?.setCurrentTimeFromSeconds(position, duration: duration)
}
self.onProgress([
@@ -301,12 +303,14 @@ extension MpvPlayerView: MPVSoftwareRendererDelegate {
guard let self else { return }
// Don't update intendedPlayState here - it's only set by user actions (play/pause)
// This prevents PiP UI flicker during seeking
// Sync timebase rate with actual playback state
self.pipController?.setPlaybackRate(isPaused ? 0.0 : 1.0)
self.onPlaybackStateChange([
"isPaused": isPaused,
"isPlaying": !isPaused,
])
// Note: Don't call updatePlaybackState() here to avoid flicker
// PiP queries pipControllerIsPlaying when it needs the state
}
}
@@ -343,12 +347,14 @@ extension MpvPlayerView: PiPControllerDelegate {
print("PiP will start")
// Sync timebase before PiP starts for smooth transition
renderer?.syncTimebase()
pipController?.updatePlaybackState()
// Set current time for PiP progress bar
pipController?.setCurrentTimeFromSeconds(cachedPosition, duration: cachedDuration)
}
func pipController(_ controller: PiPController, didStartPictureInPicture: Bool) {
print("PiP did start: \(didStartPictureInPicture)")
pipController?.updatePlaybackState()
// Ensure current time is synced when PiP starts
pipController?.setCurrentTimeFromSeconds(cachedPosition, duration: cachedDuration)
}
func pipController(_ controller: PiPController, willStopPictureInPicture: Bool) {
@@ -371,12 +377,16 @@ extension MpvPlayerView: PiPControllerDelegate {
func pipControllerPlay(_ controller: PiPController) {
print("PiP play requested")
play()
intendedPlayState = true
renderer?.play()
pipController?.setPlaybackRate(1.0)
}
func pipControllerPause(_ controller: PiPController) {
print("PiP pause requested")
pause()
intendedPlayState = false
renderer?.pausePlayback()
pipController?.setPlaybackRate(0.0)
}
func pipController(_ controller: PiPController, skipByInterval interval: CMTime) {
@@ -394,4 +404,8 @@ extension MpvPlayerView: PiPControllerDelegate {
func pipControllerDuration(_ controller: PiPController) -> Double {
return getDuration()
}
func pipControllerCurrentPosition(_ controller: PiPController) -> Double {
return getCurrentPosition()
}
}