首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVPlayer加载速度慢

AVPlayer加载速度慢
EN

Stack Overflow用户
提问于 2017-02-05 22:56:32
回答 3查看 4.9K关注 0票数 8

我正在使用AVPlayer播放来自远程url的mp3文件。我对mp3的初始加载时间有一些问题,它非常慢(大约5-8秒)。

我将它与其他第三方播放器进行了比较,它的速度要慢得多,我还将它与android播放器进行了比较,它的速度也要慢得多。

所以问题不在于url本身,也不在于网络连接。

另一个有趣的点是,在AVPlayer开始播放mp3之后,seeking速度非常快(几乎立即),这是否意味着播放器在开始播放之前下载了整个mp3文件,这就是它如此慢的原因?

我能控制这种行为吗?如果没有,还有其他想法吗?原因是什么?

EN

回答 3

Stack Overflow用户

发布于 2017-02-08 00:08:49

AVPlayer有一些新功能(针对iOS 10+),您可以试用一下。我自己使用了它,一切都运行正常。

代码语言:javascript
复制
/*!
 @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来查看它):

代码语言:javascript
复制
   /*!
     @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);
票数 2
EN

Stack Overflow用户

发布于 2019-05-01 03:29:54

对于iOS 10.x或更高版本,为了减少缓慢的加载时间,我设置了:avplayer.automaticallyWaitsToMinimizeStalling = false;,这似乎为我解决了这个问题。这可能会有其他后果,但我还没有达到这些结果。

我的想法来自于:AVPlayer stops playing video after buffering

票数 0
EN

Stack Overflow用户

发布于 2017-02-11 14:07:14

这是我对它的看法。

不同文件有不同的移动原子,所以如果在这样的文件中,如果移动原子先出现,那么这个文件就会使用缓冲。因此,这个文件随部分下载,并通过缓冲继续播放。

在其他情况下,在文件移动原子最后,然后首先下载整个文件,然后播放。所以我认为这就是你的情况,这就是为什么mp3在下载整个mp3时会延迟一段时间。

您可以通过编码将move atom更改为这样的文件。查看此答案Move and fix moov atom of video recorded on phone iOS

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42053476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档