我正在开发一个实时视频播放器,我想使用新的画中画选项。我将播放器基于AVPlayerViewController,这是我的代码。
class PlayerViewController: AVPlayerViewController {
var link = NSURL ()
override func viewDidLoad() {
super.viewDidLoad()
setVideoPlayer()
do {
try AVAudioSession.sharedInstance().setActive(true)
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
}
catch {
print("Audio session setCategory failed")
}
}
}
typealias VideoPlayer = PlayerViewController
extension VideoPlayer {
func setVideoPlayer() {
player = AVPlayer(URL: (link))
player!.play()
}
}
我不明白为什么PictureInPicture在iPad Air 2模拟器上运行良好但在真实设备中PiP按钮虽然可见但仍保持禁用状态,但用户无法点击它。
答案 0 :(得分:3)
确保在AppDelegate.swift func应用程序中设置音频会话(application:,didFinishLaunchingWithOptions launchOptions :),在示例代码下面找到。
let audioSssn = AVAudioSession.sharedInstance();
do {
try audioSssn.setCategory(AVAudioSessionCategoryPlayback)
}
catch {
print("Audio session setCategory failed")
}