2017-02-05 148 views
5

我使用AVPlayer从远程URL播放MP3文件。 我有一些与MP3的初始加载时间有关的问题,它非常慢(约5-8秒)。
我把它与其他第三方玩家相比,它的速度慢得多,我也把它与一个android玩家相比,它也慢得多。
所以这个问题是不是与URL本身也不与网络连接..AVPlayer缓慢加载

另一个有趣的一点是,AVPlayer开始播放MP3后,追求的是速度非常快(几乎立即),这是否意味着该播放器下载整个MP3文件开始播放之前,这就是它如此缓慢的原因?
我可以控制这种行为吗?如果没有,任何其他想法可能是什么原因?

+0

也许相关:http://stackoverflow.com/questions/11171374/how-to-reduce-ios-avplayer-start-delay – Lukas

回答

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); 

另外你可以看看这个变量(可以使用国际志愿者组织来说太):

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

在这里,我想什么了。

不同的文件有不同的移动原子,所以如果在这样的文件中如果移动原子先来了,那么这个文件就会缓冲起来。所以这个文件与部分下载,它继续缓冲。

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

您可以通过编码将移动原子转换为此类文件。看看这个答案Move and fix moov atom of video recorded on phone iOS

+0

AFAIK,MP3文件没有MOOV原子,因为那些特定于MPEG4视频流。 – Jules