5

Is it possible to know when an AVAudioPlayer is ready after a call to prepareToPlay?

If not, is there any other class that provides this functionality?

I would like to implement something like this:

- (void) prepare {
    [audioPlayer prepareToPlay];
    // Update UI to indicate that the audio is being prepared
}

- (void) onAudioReady {
    // Update UI to indicate that the audio is ready
}
hpique
  • 119,096
  • 131
  • 338
  • 476

1 Answers1

0

There is this class that can help to initialize the audio and then play it instantly in your onAudioReady method.

https://github.com/nicklockwood/SoundManager

with reference to this post: https://stackoverflow.com/a/10417762/1474080

OR

you can check for the BOOL result from [audioPlayer prepareToPlay] to see if the audio hardware has been initialised according to the documentation. If the result is YES, you could generate some UI for user to see.

prepareToPlay Prepares the audio player for playback by preloading its buffers.

  • (BOOL)prepareToPlay Return Value Returns YES on success, or NO on failure.

Discussion Calling this method preloads buffers and acquires the audio hardware needed for playback, which minimizes the lag between calling the play method and the start of sound output.

Calling the stop method, or allowing a sound to finish playing, undoes this setup.

Community
  • 1
  • 1
edwardlayys
  • 79
  • 10