ios - AVPlayer如何管理不同的URL

标签 ios avplayer

我正在尝试做一个小型广播应用程序,我得到了传递给 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 列表。 AVPlayerAVPlayerItem 能够播放 m3u8 文件 - 即 UTF8 编码的 m3u 文件。

您是否尝试过在 Mobile Safari 中打开这些 URL?如果它们在那里不起作用,则 AVPlayer 可能也不支持该格式。

无论如何 - 如果您可以提供实际有问题的 URL,则可以检查实际的文件格式。

“compositor”的意思是“Quartz compositor”——忘记这一点,这里不相关。 [编辑:也许它是相关的 - 在你对此答案发表评论后我傻眼了......]

关于ios - AVPlayer如何管理不同的URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700635/

相关文章:

objective-c - 如何获取 AVPlayer 的视频帧?

ios - UITabBarController 图标未显示

php - 一次发送多个 POST 请求

iOS Storyboard传递数据 navigationViewController

ios - 搜索 Display Controller is Deprecated in iOS8

ios - 欢迎屏幕中的视频使用 AVPlayer 导致内存泄漏?

iphone - AVPlayer 不播放视频文件

ios - 将 View Controller 添加到 UICollectionViewCell

ios - 暂停播放时 MPNowPlayingInfoCenter react 不正确

ios - AVPlayerViewController 是否自动带有 AVPlayer 对象?