I know this has been asked before, but the responses are out-of-date. I am using Swift 4 for iOS11+. I have an AVPlayerViewController that plays either a downloaded MP4 (this works fine), or a stream from the server (doesn't play). I have also tested playing a non-streamed version of the video from the server and this works fine too. So, the problem seems to be with the HLS stream.
I get the following log in the console when I load the 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)'
The stream URL is passed into the AVPlayer like so:
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)
})
}
}
Any ideas? I have read posts that tell you to use KVC to check for the status property of the player, but I thought all this was old-school, and the AVPlayer should be able to handle proper video streams now.