AVPlayer检测到不受支持的视频的播放错误

时间:2018-08-23 07:12:25

标签: swift video-streaming avplayer

我正在尝试播放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

如何检测播放器是否支持特定的视频网址?

0 个答案:

没有答案