AVPlayer not playing m3u8 from local file

匿名 (未验证) 提交于 2019-12-03 01:11:01

问题:

I am trying to get AVPlayer to play a m3u8 playlist that is a local file.

I have narrowed this down to a simple test case using one of Apple's sample playlists:

https://tungsten.aaplimg.com/VOD/bipbop_adv_fmp4_example/master.m3u8 

If i play this playlist from the remote url, AVPlayer plays this fine. However, if i download this playlist to a local file, and then hand AVPlayer the local file URL, AVPlayer will not play it. It just shows the crossed out play symbol.

Interestingly enough, this can be duplicated with Safari as well. Safari will play the remote playlist but not the local file. Also of note is that this behavior of AVPlayer is identical on iOS 10.2 as well as macOS 10.12.1. Also, playing an mp4 media file directly (not wrapped in a playlist) does not seem to have this issue, as it plays both from a remote URL as well as from a local file.

Inspecting the AVPlayerItem.error does not lead to anything useful either:

An unknown error occurred (-12865) The operation could not be completed 

Is anyone aware of any limitation that AVPlayer would not play a local playlist?

Thank you.

回答1:

m3u/m3u8 files must be stored on a server and streamed in order to be played(I know it sounds not reasonable, but Apple did it again). You must use HLS, which basically means you should store the file on a server and directly access it from there. You can as well create a local Server inside your app using a framework like GCD WebServer.



回答2:

As of iOS 10 you can download HLS streams using AVAssetDownloadURLSession . This will result in a local asset path that can be played offline.

If you are trying to embed a video in your app bundle you would be better off just creating an MP4.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!