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

View File

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