mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add PiP for iOS
This commit is contained in:
35
Model/Player/PiPDelegate.swift
Normal file
35
Model/Player/PiPDelegate.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
import AVKit
|
||||
import Foundation
|
||||
|
||||
final class PiPDelegate: NSObject, AVPictureInPictureControllerDelegate {
|
||||
var player: PlayerModel!
|
||||
|
||||
func pictureInPictureController(
|
||||
_: AVPictureInPictureController,
|
||||
failedToStartPictureInPictureWithError error: Error
|
||||
) {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
|
||||
func pictureInPictureControllerWillStartPictureInPicture(_: AVPictureInPictureController) {}
|
||||
|
||||
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {}
|
||||
|
||||
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
|
||||
if player?.avPlayerBackend.switchToMPVOnPipClose ?? false {
|
||||
DispatchQueue.main.async { [weak player] in
|
||||
player?.avPlayerBackend.switchToMPVOnPipClose = false
|
||||
player?.saveTime { [weak player] in
|
||||
player?.changeActiveBackend(from: .appleAVPlayer, to: .mpv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pictureInPictureControllerWillStopPictureInPicture(_: AVPictureInPictureController) {}
|
||||
|
||||
func pictureInPictureController(
|
||||
_: AVPictureInPictureController,
|
||||
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler _: @escaping (Bool) -> Void
|
||||
) {}
|
||||
}
|
Reference in New Issue
Block a user