AVPlayer不播放视频流

时间:2018-01-12 12:29:56

标签: ios swift avplayer avplayerviewcontroller avplayeritem

我知道以前曾经问过,但回复已经过时了。我正在使用Swift 4 for iOS11 +。我有一个AVPlayerViewController播放下载的MP4(这很好),或者来自服务器的流(不播放)。我还测试了从服务器播放视频的非流式版本,这也很好用。所以,问题似乎与HLS流有关。

加载VC时,我在控制台中收到以下日志:

2018-01-12 12:21:56.395018+0000 PDC[26716:3853600] [] <<<< AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery mode to DiscoveryMode_Presence (client: PDC)
2018-01-12 12:21:56.645069+0000 PDC[26716:3853600] [framework] CUICatalog: Invalid asset name supplied: '(null)'

将流URL传递到AVPlayer,如下所示:

if let vidUrl = isDownloaded ? DownloadManager.shared.getFileUrl(forFileId: caseStudy.id!) : URL(string:caseStudy.videoStreamURL!)! {
    if isDownloaded {

        let asset = AVURLAsset(url: vidUrl)
        let item = AVPlayerItem(asset: asset)
        vc.player = AVPlayer(playerItem: item)

    }else{

        vc.player = AVPlayer(url: vidUrl)
        vc.player?.play()
    }

    if vc.navigationController != nil {

        vc.navigationController!.isNavigationBarHidden = true
        NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: vc, queue: nil, using: { (notification) in

            vc.dismiss(animated: true, completion: nil)
        })
    }
}

有什么想法吗?我已经阅读过帖子,告诉你使用KVC来检查播放器的状态属性,但我认为这一切都是老式的,AVPlayer应该能够处理正确的视频流。

0 个答案:

没有答案