0

I have created by AVQueuePlayer to load audio. The source is from the audio file. When it comes to the execution, I find out that it takes 6-7 seconds to play next video. Would you please tell me the way to optimise the downloading time and minimise the waiting time to load next audio ?

here is my code:

let url = URL(string: (audio?.audio_path)!)
let playerItem:AVPlayerItem = AVPlayerItem(url: url!)
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141

1 Answers1

1

I have answered a question about slow loading in this thread.

AVPlayer has functionality (from 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);

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);
Georgi Boyadzhiev
  • 1,351
  • 1
  • 13
  • 18