AVPlayer-获取可用带宽/比特率流的列表并强制其中之一 [英] AVPlayer - get the list of available bandwidth/bitrate streams and force one of them
问题描述
我正在尝试在iOS AVFoundation上动态播放视频时更改播放比特率.
在此流中: https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8 ,有5个视频比特率,现在AV会自动选择比特率.
I'm trying to change the playback bitrate while the video is playing dynamically on iOS AVFoundation.
In this stream: https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8, there are 5 video bitrates and now the AV chooses the bitrate automatically.
我想允许用户选择HD质量,因此我需要一种方法来迫使播放器选择最高比特率而不替换源.
I want to allow the user to select HD quality, so I need a way to force the player to choose the highest bitrate without replacing the source.
推荐答案
The Apple's documentation for [AVPlayerItem]
(see docs) has the preferredPeakBitRate:
method described as:
此项目所需的网络带宽消耗限制,以每秒位数为单位.
The desired limit, in bits per second, of network bandwidth consumption for this item.
如果无法降低网络带宽消耗以达到PreferredPeakBitRate,则在继续播放该项目时会尽可能降低它.
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.
AVPlayerItem:配置网络行为 [在线].[引用.2017-02-14].可从以下网站获得: https://developer.apple.com/reference/avfoundation/avplayeritem
AVPlayerItem: Configuring Network Behaviour [online]. [cit. 2017-02-14]. Available from: https://developer.apple.com/reference/avfoundation/avplayeritem
这并不是每个人都会说的硬性限制,但是如果连接可以支持比特率(如iOS所认为的),那么它将尝试满足期望.
It isn't hard-limit per say, but if the connection can support the bitrate (as deemed by the iOS) then it tries to meet the expectations.
关于可用比特率的列表,您需要手动解析 m3u8
文件或自行创建级别.
As for the list of available bitrates you would need to manually parse the m3u8
file or just create the levels yourself.
这篇关于AVPlayer-获取可用带宽/比特率流的列表并强制其中之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!