使用 AVPlayer 进行 HTTP 实时音频流时,有没有办法选择比特率?
我正在使用 AVPlayer 来流式传输以两种质量格式提供的音频内容。
问题是,当从较低格式传递到较高格式时(当 Wi-Fi 可用时由框架自动完成),播放时会出现延迟。
有没有办法手动选择所需的质量以防止这种延迟?
I'm using AVPlayer to stream audio content delivered in two quality formats.
The problem is that when passing from a lower format to a higher one ( done automatically by the framework when wi-fi is available ) there is a delay while playing.
Is there a way to manually select a desired quality in order to prevent that delay?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
现在在 iOS8 中可以实现。
在 AVPlayerItem 上查看 preferredPeakBitRate。
以下内容摘自Apple的文档:
It's possible now in iOS8.
Checkout preferredPeakBitRate on AVPlayerItem.
Following copied from Apple's documentation:
更新:这在当时的 iOS 4 中是准确的。有关更新的 iOS 8 答案,请参阅此处。
我自己研究过这个问题,但没有找到答案,这意味着我非常肯定没有办法做到这一点。 Apple 文档并不总是提供您可以使用事物做什么的所有细节,但是如果您查看所有可用的属性、方法等,您会发现没有任何内容可以让您调整流。
我认为这就是 HLS 的全部意义所在。 Apple 希望 iPhone 用户能够获得最佳的流媒体体验。如果他们为开发人员提供了调整正在使用的流的控件,那么就达不到目的了。当涉及到切换流时,系统最了解。如果手机无法处理额外的带宽,那么它不会(或不应该)切换到更高的流。我发现您可能想要查看的一些内容...
您的文件是否以 10 秒为增量进行分块?如果超过这个数,您可能需要缩短它们。
某些文件转换程序无法获得完全正确的比特率,如果是这种情况,您的手机可能会认为它具有 96 kbps 源的带宽,但实际上您的源是 115 kbps。看看这篇文章中接受的答案:iPhone - 应用程序再次被拒绝,HTTP 实时流媒体 64kbps 基线提要
Update: This was accurate at the time for iOS 4. For an updated iOS 8 answer, see here.
I've researched this very question for myself and have not found an answer which means I'm pretty positive there is no way to do this. The Apple docs don't always give all the details of what you can do with things but if you look at all the available properties, methods, etc you will find that there is nothing to allow you to tweak the stream.
I think this is the whole point of HLS. Apple wants iPhone users to have the best streaming experience possible. If they gave the developer the controls to tweak which stream is being used then that defeats the purpose. The system knows best when it comes to switching streams. If the phone cannot handle the additional bandwidth then it won't (or shouldn't) switch to the higher stream. Some things that I have found that you may want to look at...
Are your files chunked into 10 second increments? If it's more than that you might want to shorten them.
Some file conversion programs don't get the bit rates exactly right and if that is the case your phone may think it has the bandwidth for, say, a 96 kbps feed but in reality your feed is 115 kbps. Take a look at the accepted answer in this post: iPhone - App Rejected again, HTTP Live Streaming 64kbps baseline feed
Use Pantomime,是一个适用于 iOS、OSX 和 tvOS 的轻量级框架,可以读取和解析 HTTP Live Streaming 清单。
哑剧
Use Pantomime, is a lightweight framework for iOS, OSX and tvOS that can read and parse HTTP Live Streaming manifests.
Pantomime