我正在尝试做一个小型广播应用程序,我得到了一个我传递给 AVPlayer 的 URL 列表,但我不明白如何管理不同的 URL。
例如,如果我第一次播放此 URL:http://www.example.com/file.mp3 然后我调用 http://www.example.net/file2.mp3 它工作正常,但是当我选择 http://www.example.org/file.mp3.m3u它不会加载那个 URL 并且 AVPlayer 不会播放。
这是我使用的代码:
urlStream = [NSURL URLWithString:mp3URL];
appDelegate = [[UIApplication sharedApplication]delegate];
playerItem = [AVPlayerItem playerItemWithURL:urlStream];
playerItem addObserver:self forKeyPath"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
[appDelegate.player replaceCurrentItemWithPlayerItem:playerItem];
我使用 replaceCurrentItemWithPlayerItem:playerItem
因为如果我在选择另一个流时使用 initWithPlayerItem
我就无法停止之前的播放:所以停止播放的唯一方法流并开始另一个是使用 replaceCurrentItemWithPlayerItem
。
在 Apple 文档中,我读到 replaceCurrentItemWithPlayerItem
必须具有与其替换的项目相同的“合成器”:什么是合成器?
我看到前两个流和第三个流(在上面的示例中)之间的不同之处在于文件扩展名。
任何建议在哪里寻找将不胜感激。
问题似乎不在于项目的替换,而是特定文件的文件格式。尝试先打开 m3u 文件 - 可能也会失败。
m3u-URL 表明这不是一个 mp3 文件,而是一个 m3u 文件 - 这是一个媒体文件的 URL 列表。 AVPlayer
和 AVPlayerItem
能够播放 m3u8 文件 - 即 UTF8 编码的 m3u 文件。
您是否尝试过在 Mobile Safari 中打开这些 URL?如果它们在那里不起作用,则 AVPlayer
可能也不支持该格式。
无论如何 - 如果您可以提供实际有问题的 URL,则可以检查实际的文件格式。
对于“compositor”,“Quartz compositor”的意思是——忘了这个,这里不相关。 [编辑:也许它是相关的 - 在你对这个答案发表评论后我傻眼了......]
关于ios - AVPlayer 如何管理不同的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700635/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) | Powered by Discuz! X3.4 |