PiP improvements

This commit is contained in:
Arkadiusz Fal
2022-08-19 00:40:46 +02:00
parent ace8c6e3ff
commit 6c6ba19df4
16 changed files with 120 additions and 162 deletions

View File

@@ -35,10 +35,7 @@ final class AVPlayerBackend: PlayerBackend {
var aspectRatio: Double {
#if os(iOS)
guard let view = model?.playerLayerView else { return VideoPlayerView.defaultAspectRatio }
let videoRect = view.playerLayer.videoRect
return videoRect.width / videoRect.height
playerLayer.videoRect.width / playerLayer.videoRect.height
#else
VideoPlayerView.defaultAspectRatio
#endif
@@ -54,7 +51,10 @@ final class AVPlayerBackend: PlayerBackend {
}
private(set) var avPlayer = AVPlayer()
var controller: AppleAVPlayerViewController?
private(set) var playerLayer = AVPlayerLayer()
#if os(tvOS)
var controller: AppleAVPlayerViewController?
#endif
var startPictureInPictureOnPlay = false
private var asset: AVURLAsset?
@@ -79,6 +79,8 @@ final class AVPlayerBackend: PlayerBackend {
addFrequentTimeObserver()
addInfrequentTimeObserver()
addPlayerTimeControlStatusObserver()
playerLayer.player = avPlayer
}
func bestPlayable(_ streams: [Stream], maxResolution _: ResolutionSetting) -> Stream? {
@@ -157,39 +159,9 @@ final class AVPlayerBackend: PlayerBackend {
avPlayer.replaceCurrentItem(with: nil)
}
#if os(tvOS)
func closePiP(wasPlaying: Bool) {
let item = avPlayer.currentItem
let time = avPlayer.currentTime()
avPlayer.replaceCurrentItem(with: nil)
guard !item.isNil else {
return
}
avPlayer.seek(to: time)
avPlayer.replaceCurrentItem(with: item)
guard wasPlaying else {
return
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.play()
}
}
#else
func closePiP(wasPlaying: Bool) {
model.pipController?.stopPictureInPicture()
guard wasPlaying else {
return
}
play()
}
#endif
func closePiP() {
model.pipController?.stopPictureInPicture()
}
private func loadSingleAsset(
_ url: URL,

View File

@@ -324,7 +324,7 @@ final class MPVBackend: PlayerBackend {
client?.stop()
}
func closePiP(wasPlaying _: Bool) {}
func closePiP() {}
func updateControls() {
self.logger.info("updating controls")

View File

@@ -45,7 +45,7 @@ protocol PlayerBackend {
func closeItem()
func closePiP(wasPlaying: Bool)
func closePiP()
func updateControls()
func startControlsUpdates()