I have an iphone app where I am playing a sound with one button using an AVAudioPlayer object. However, I would like to use a variable for the sound name and send a value to that variable. I have two other buttons that play different sounds and would like to send the sound name values to the variable that is in the AVAudioPlayer. How d开发者_JS百科o I do that?
Thanks!
you can keep your audio files (in resource) with numeric names such as 1.mp3, 20.mp3, 41.wav etc and then you can use [NSString stringWithFormat:@"%d.mp3",soundId]; to generate sound file name to use generating absolute resource path and pass it to AVAudioPLayer
Best of Luck!!
This cannot be done. Create a new AVAudioPlayer for each new sound. If you wish to interrupt the current sound, send stop to the current instance.
精彩评论