使用 AVPlayer 进行 HTTP 实时音频流时,有没有办法选择比特率?

发布于 2024-10-22 17:15:28 字数 130 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铁轨上的流浪者 2024-10-29 17:15:28

现在在 iOS8 中可以实现。

在 AVPlayerItem 上查看 preferredPeakBitRate

以下内容摘自Apple的文档:

此项所需的网络带宽消耗限制(以每秒位数为单位)。
SWIFT:var PreferredPeakBitRate:Double
目标-C:@property(非原子)双首选PeakBitRate

将 PreferredPeakBitRate 设置为非零,以指示播放器应尝试将项目播放限制为该比特率(以每秒位数表示)。

如果无法降低网络带宽消耗以满足preferredPeakBitRate,则会在继续播放该项目的同时尽可能减少网络带宽消耗。

It's possible now in iOS8.

Checkout preferredPeakBitRate on AVPlayerItem.

Following copied from Apple's documentation:

The desired limit, in bits per second, of network bandwidth consumption for this item.
SWIFT: var preferredPeakBitRate: Double
OBJECTIVE-C: @property(nonatomic) double preferredPeakBitRate

Set preferredPeakBitRate to non-zero to indicate that the player should attempt to limit item playback to that bit rate, expressed in bits per second.

If network bandwidth consumption cannot be lowered to meet the preferredPeakBitRate, it will be reduced as much as possible while continuing to play the item.

无所的.畏惧 2024-10-29 17:15:28

更新:这在当时的 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

秋凉 2024-10-29 17:15:28

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文