2017-02-05 193 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