How to know EXACTLY why a sound starts playing?
I need to play an audio clip in mp3 format and synchronize something in my app with the audio being played. What audio tools in the iPhone SDK should I use to allow me to know exactly when the selected sound starts to play?
Sometime开发者_StackOverflows with AVAudioPlayer I notice that when a sound starts to play there is a slight delay from when I command the player to play, and when I actually hear the sound (I'm guessing it's loading the sound during that time). There is no 'ready to play' delegate methods that I can find for AVAudioPlayer.
Any suggestions/pointers appreciated.
If you want to minimise any potential delay, you should use the AVAudioPlayer class prepareToPlay
method (if you're not already doing so) prior to when you'll need the sound and then call play
when you want playback to start.
How close synchronization do you need? With mp3, there is always some decoding uncertainty, so you need to prepareToPlay ahead of time to remove some of that.
But even better for the lowest possible delay is to feed raw PCM samples to the Audio Unit RemoteIO API, which can usually get you within better than one 60 Hz video frame of latency.
to get accurate synchronization of your audio playback, you'll need to use Audio Queue Services. It's a C interface offering finer-grained control of audio. I won't be able to tell you exactly how to sync up because I've no experience with that aspect of it, maybe someone else can help. But if you look at the docs hopefully that will steer you in the right direction.
精彩评论