mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 22:30:32 +05:30
PiP improvements
This commit is contained in:
parent
a67a96cfa0
commit
eb7cca1c56
@ -37,7 +37,7 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
|
||||
private(set) var avPlayer = AVPlayer()
|
||||
var controller: AppleAVPlayerViewController?
|
||||
var enterPiPOnPlay = false
|
||||
var startPictureInPictureOnPlay = false
|
||||
var switchToMPVOnPipClose = false
|
||||
|
||||
private var asset: AVURLAsset?
|
||||
@ -323,6 +323,8 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.setRate(self.model.currentRate)
|
||||
}
|
||||
|
||||
let replaceItemAndSeek = {
|
||||
@ -442,7 +444,7 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
self,
|
||||
selector: #selector(itemDidPlayToEndTime),
|
||||
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
||||
object: playerItem
|
||||
object: model.playerItem
|
||||
)
|
||||
}
|
||||
|
||||
@ -450,7 +452,7 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
NotificationCenter.default.removeObserver(
|
||||
self,
|
||||
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
||||
object: playerItem
|
||||
object: model.playerItem
|
||||
)
|
||||
}
|
||||
|
||||
@ -470,6 +472,9 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
model.hide()
|
||||
#endif
|
||||
} else {
|
||||
if model.playingInPictureInPicture {
|
||||
startPictureInPictureOnPlay = true
|
||||
}
|
||||
model.advanceToNextItem()
|
||||
}
|
||||
}
|
||||
@ -538,10 +543,10 @@ final class AVPlayerBackend: PlayerBackend {
|
||||
if player.timeControlStatus != .waitingToPlayAtSpecifiedRate {
|
||||
if let controller = self.model.pipController {
|
||||
if controller.isPictureInPicturePossible {
|
||||
if self.enterPiPOnPlay {
|
||||
self.enterPiPOnPlay = false
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.model.pipController?.startPictureInPicture()
|
||||
if self.startPictureInPictureOnPlay {
|
||||
self.startPictureInPictureOnPlay = false
|
||||
DispatchQueue.main.async {
|
||||
self.model.pipController?.startPictureInPicture()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +201,8 @@ final class MPVBackend: PlayerBackend {
|
||||
startControlsUpdates()
|
||||
}
|
||||
|
||||
setRate(model.currentRate)
|
||||
|
||||
client?.play()
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,10 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
|
||||
|
||||
func pictureInPictureControllerWillStartPictureInPicture(_: AVPictureInPictureController) {}
|
||||
|
||||
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {}
|
||||
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
|
||||
player?.playingInPictureInPicture = true
|
||||
player?.avPlayerBackend.startPictureInPictureOnPlay = false
|
||||
}
|
||||
|
||||
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
|
||||
if player?.avPlayerBackend.switchToMPVOnPipClose ?? false {
|
||||
@ -24,12 +27,16 @@ final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player?.playingInPictureInPicture = false
|
||||
}
|
||||
|
||||
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {}
|
||||
|
||||
func pictureInPictureController(
|
||||
_: AVPictureInPictureController,
|
||||
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler _: @escaping (Bool) -> Void
|
||||
) {}
|
||||
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
|
||||
) {
|
||||
completionHandler(true)
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
final class PlayerControlsModel: ObservableObject {
|
||||
@Published var isLoadingVideo = true
|
||||
@Published var isLoadingVideo = false
|
||||
@Published var isPlaying = true
|
||||
@Published var currentTime = CMTime.zero
|
||||
@Published var duration = CMTime.zero
|
||||
|
@ -343,7 +343,6 @@ final class PlayerModel: ObservableObject {
|
||||
}
|
||||
|
||||
inactiveBackends().forEach { $0.pause() }
|
||||
backend.setRate(currentRate)
|
||||
|
||||
let fromBackend: PlayerBackend = from == .appleAVPlayer ? avPlayerBackend : mpvBackend
|
||||
let toBackend: PlayerBackend = to == .appleAVPlayer ? avPlayerBackend : mpvBackend
|
||||
|
@ -111,7 +111,6 @@ extension PlayerModel {
|
||||
remove(newItem)
|
||||
|
||||
currentItem = newItem
|
||||
pause()
|
||||
|
||||
accounts.api.loadDetails(newItem) { newItem in
|
||||
self.playItem(newItem, video: newItem.video, at: time)
|
||||
@ -152,7 +151,6 @@ extension PlayerModel {
|
||||
if play {
|
||||
currentItem = item
|
||||
// pause playing current video as it's going to be replaced with next one
|
||||
pause()
|
||||
}
|
||||
|
||||
queue.insert(item, at: prepending ? 0 : queue.endIndex)
|
||||
|
@ -252,7 +252,7 @@ struct PlayerControls: View {
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||
print(player.pipController?.isPictureInPicturePossible ?? false ? "possible" : "NOT possible")
|
||||
player.avPlayerBackend.enterPiPOnPlay = true
|
||||
player.avPlayerBackend.startPictureInPictureOnPlay = true
|
||||
player.pipController?.startPictureInPicture()
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ struct PlayerQueueRow: View {
|
||||
Button {
|
||||
player.prepareCurrentItemForHistory()
|
||||
|
||||
player.avPlayerBackend.startPictureInPictureOnPlay = player.playingInPictureInPicture
|
||||
|
||||
if history {
|
||||
player.playHistory(item, at: watchStoppedAt)
|
||||
} else {
|
||||
|
@ -91,6 +91,8 @@ struct VideoCell: View {
|
||||
playAt = .secondsInDefaultTimescale(watch!.stoppedAt)
|
||||
}
|
||||
|
||||
player.avPlayerBackend.startPictureInPictureOnPlay = player.playingInPictureInPicture
|
||||
|
||||
player.play(video, at: playAt, inNavigationView: inNavigationView)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user