Fix auto play video settings close #636

This commit is contained in:
Thomas Ricouard 2023-02-04 07:53:03 +01:00
parent 71f6cfd52a
commit 1bf36670e2

View file

@ -16,12 +16,16 @@ class VideoPlayerViewModel: ObservableObject {
player?.audiovisualBackgroundPlaybackPolicy = .pauses
if autoPlay {
player?.play()
} else {
player?.pause()
}
guard let player else { return }
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime,
object: player.currentItem, queue: .main) { [weak self] _ in
self?.player?.seek(to: CMTime.zero)
self?.player?.play()
if autoPlay {
self?.player?.seek(to: CMTime.zero)
self?.player?.play()
}
}
}
@ -55,7 +59,9 @@ struct VideoPlayerView: View {
case .background, .inactive:
viewModel.pause()
case .active:
viewModel.play()
if preferences.autoPlayVideo {
viewModel.play()
}
default:
break
}