Fix pausing on dismissing player

This commit is contained in:
Arkadiusz Fal 2021-11-05 15:58:51 +01:00
parent e2e864e9da
commit 1d8efbda58
2 changed files with 9 additions and 6 deletions

View File

@ -21,7 +21,7 @@ final class PlayerModel: ObservableObject {
var avPlayerViewController: AVPlayerViewController? var avPlayerViewController: AVPlayerViewController?
#endif #endif
@Published var presentingPlayer = false @Published var presentingPlayer = false { didSet { pauseOnPlayerDismiss() } }
@Published var stream: Stream? @Published var stream: Stream?
@Published var currentRate: Float = 1.0 { didSet { player.rate = currentRate } } @Published var currentRate: Float = 1.0 { didSet { player.rate = currentRate } }
@ -143,6 +143,14 @@ final class PlayerModel: ObservableObject {
updateCurrentArtwork() updateCurrentArtwork()
} }
private func pauseOnPlayerDismiss() {
if !playingInPictureInPicture, !presentingPlayer {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.pause()
}
}
}
private func insertPlayerItem( private func insertPlayerItem(
_ stream: Stream, _ stream: Stream,
for video: Video, for video: Video,

View File

@ -118,11 +118,6 @@ struct VideoPlayerView: View {
} }
#endif #endif
} }
.onDisappear {
if !player.playingInPictureInPicture {
player.pause()
}
}
} }
func playerPlaceholder(geometry: GeometryProxy) -> some View { func playerPlaceholder(geometry: GeometryProxy) -> some View {