AVPlayer缓慢加载 [英] AVPlayer slow loading

查看:312
本文介绍了AVPlayer缓慢加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVPlayer从远程URL播放mp3文件. 我在mp3的初始加载时间上遇到了一些问题,它非常慢(大约5-8秒).
我将其与其他第三方播放器进行了比较,并且速度要慢得多,也将其与Android播放器进行了比较,并且速度也要慢得多.
因此问题不在于URL本身,也不在于网络连接.

I'm using AVPlayer to play mp3 files from a remote url. i'm having some issues with the initial loading time of the mp3, it is very slow (around 5-8 sec).
i compared it with other third parties players and its much slower, i also compared it with an android player and it is also much slower.
so the problem is not with the url itself nor with the network connection..

另一个有趣的一点是,在AVPlayer开始播放mp3之后,搜索非常快(几乎立即进行),这是否意味着播放器在开始播放之前就下载了整个mp3文件,这就是为什么它这么慢的原因吗?
我可以控制这种行为吗?如果没有,还有其他想法可能是什么原因?

another interesting point is that after the AVPlayer start playing the mp3, seeking is very fast (almost immediately), does that mean the player download the entire mp3 file before start playing, and thats the reason it is so slow?
can i control this behaviour? if not, any other ideas what can be the reason?

推荐答案

AVPlayer具有一些新功能(适用于iOS 10及更高版本),您可以尝试一下.我自己使用了它,一切正常.

AVPlayer has some new functionality (for iOS 10+), that You can try out. I used it myself and everything was working properly.

/*!
 @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):

Additionally You can check out this variable (You can use KVO for it too):

   /*!
     @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);

这篇关于AVPlayer缓慢加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆