Slow loading AVPlayer

I am using AVPlayer to play mp3 files from a remote URL. I am having problems with the initial mp3 download time, it is very slow (about 5-8 seconds).
I compared it to other third party players and it is much slower, I also compared it to an android player and it is also much slower. therefore, the problem is not with the URL itself, nor with the network connection.

Another interesting point: after AVPlayer starts playing mp3, the search is very fast (almost immediately), does this mean that the player downloads the entire mp3 file before starting to play, and for this reason it is so slow?
can i control this behavior? if not, could any other ideas be the reason?

+6
source share
3 answers

AVPlayer has some new features (for iOS 10+) that you can try. I used it myself, and everything worked correctly.

 /*! @method playImmediatelyAtRate: @abstract Immediately plays the available media data at the specified rate. @discussion When the player 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 (eg 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); 

Additionally you can check this variable (you can also use 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 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
source

For iOS 10.x or higher, to reduce the slow loading time, I set: avplayer.automaticallyWaitsToMinimizeStalling = false; and that seemed to fix it for me. This may have other consequences, but I have not hit them yet.

I got an idea from this: AVPlayer stops playing videos after buffering

0
source

Here is what I think of it.

There are different displacement atoms in this other file. Therefore, if in such a file, if the atom came first, this file plays with buffering. Thus, this file is loaded using parts, and playback continues using buffering.

In another case, in the move atom file, finally, the entire entire file is first loaded, then it is played. Therefore, I think that in your case, why mp3 is delayed with some time to download all mp3.

You can change the movement of an atom to such a file using encoding. Check this answer. Move and fix atom atom of video recorded on iOS phone

-1
source

Source: https://habr.com/ru/post/1263841/


All Articles