我正在尝试播放AVPlayer
上的远程视频。播放器不支持某些视频。然后显示黑色屏幕,旋转器旋转。
我的代码是
@IBAction func playVideo(_ sender: UIButton) {
let videoUrl = "url here"
let url = URL(string: videoUrl)
let player = AVPlayer(url: url!)
player.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions(), context: nil)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
我尝试添加NSNotification.Name.AVPlayerItemFailedToPlayToEndTime/.AVPlayerItemNewErrorLogEntry/.AVPlayerItemPlaybackStalled
通知,但未收到通知。还尝试了密钥"status"
的KVO。第一次呼叫,但状态已准备就绪,播放器错误为nil
。
如何检测播放器是否支持特定的视频网址?