我正在使用AVPlayer
播放来自远程网址的mp3文件。
我对mp3的初始加载时间有一些问题,它非常慢(大约5-8秒)
我将它与其他第三方玩家进行了比较,速度要慢得多,我也将它与Android播放器进行了比较,而且速度也慢得多
所以问题不在于网址本身,也不在于网络连接..
另一个有趣的一点是,在AVPlayer
开始播放mp3后,寻求非常快(几乎立即),这是否意味着播放器在开始播放之前下载整个mp3文件,这就是它的原因慢?
我可以控制这种行为吗?如果没有,任何其他想法可能是什么原因?
答案 0 :(得分:2)
AVPlayer
有一些新功能(适用于iOS 10+),您可以尝试一下。我自己用它,一切都运转正常。
/*!
@method playImmediatelyAtRate:
@abstract Immediately plays the available media data at the specified rate.
@discussion
When the player's currentItem has a value of NO for playbackBufferEmpty, this method causes the value of rate to change to the specified rate, the value of timeControlStatus to change to AVPlayerTimeControlStatusPlaying, and the receiver to play the available media immediately, whether or not prior buffering of media data is sufficient to ensure smooth playback.
If insufficient media data is buffered for playback to start (e.g. if the current item has a value of YES for playbackBufferEmpty), the receiver will act as if the buffer became empty during playback, except that no AVPlayerItemPlaybackStalledNotification will be posted.
*/
- (void)playImmediatelyAtRate:(float)rate NS_AVAILABLE(10_12, 10_0);
此外,您可以查看此变量(您也可以使用KVO):
/*!
@property reasonForWaitingToPlay
@abstract Indicates the reason for waiting when the value of timeControlStatus is AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate
@discussion
When the value of timeControlStatus is AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate, this property describes why the player is currently waiting. It is nil otherwise.
You can use the value of reasonForWaitingToPlay to show UI indicating the player's waiting state conditionally.
This property is key value observable.
Possible values are AVPlayerWaitingWithNoItemToPlayReason, AVPlayerWaitingWhileEvaluatingBufferingRateReason, and AVPlayerWaitingToMinimizeStallsReason.
*/
@property (nonatomic, readonly, nullable) NSString *reasonForWaitingToPlay NS_AVAILABLE(10_12, 10_0);
答案 1 :(得分:0)
对于iOS 10.x或更高版本,为了减少缓慢的加载时间,我设置了:
avplayer.automaticallyWaitsToMinimizeStalling = false;
这似乎为我解决了。这可能会带来其他后果,但我还没有实现这些目标。
答案 2 :(得分:-1)
在这里,我的想法。
那个不同的文件有不同的移动原子,所以如果在这样的文件中,如果移动原子首先出现,那么这个文件将使用缓冲。所以这个文件随部件一起下载,并且它继续播放。
在其他情况下,在文件移动原子最后然后第一个整个文件下载然后它播放。因此,我认为这就是为什么mp3会因为下载整个mp3而延迟一段时间的原因。
您可以使用编码将move atom更改为此类文件。看看这个答案Move and fix moov atom of video recorded on phone iOS