AVPlayer无法从本地文件播放m3u8 [英] AVPlayer not playing m3u8 from local file

查看:854
本文介绍了AVPlayer无法从本地文件播放m3u8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让AVPlayer播放作为本地文件的m3u8播放列表.

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

我已使用Apple的示例播放列表之一将其缩小为一个简单的测试用例:

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

如果我从远程URL播放此播放列表,则AVPlayer可以正常播放.但是,如果我将此播放列表下载到本地文件,然后将本地文件URL交给AVPlayer,则AVPlayer将不会播放它.它只是显示划掉的比赛符号.

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.

足够有趣的是,它也可以与Safari复制. Safari将播放远程播放列表,但不播放本地文件.还要注意的是,AVPlayer的这种行为在iOS 10.2和macOS 10.12.1上是相同的.另外,直接播放mp4媒体文件(未包装在播放列表中)似乎也没有此问题,因为它既可以从远程URL播放,也可以从本地文件播放.

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.

检查AVPlayerItem.error不会导致任何有用的事情:

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

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

有人知道AVPlayer无法播放本地播放列表的任何限制吗?

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

谢谢.

推荐答案

m3u/m3u8文件必须存储在服务器上并进行流式播放才能播放(我知道这听起来不合理,但Apple再次这样做了).您必须使用 HLS ,这基本上意味着您应该将文件存储在服务器上并直接从那里访问.您也可以使用 GCD WebServer 之类的框架在应用程序内部创建本地服务器.

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.

这篇关于AVPlayer无法从本地文件播放m3u8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆