views:

2979

answers:

4

So I have an app which plays many short sound clips. I need to know when the sounds are finished playing, and I need to use mp3s, so I'm using AVFoundation for the sound playback.

When a sound is actively playing, and the user uses the hardware volume buttons, the playback volume changes. Problem is, the app is NOT constantly playing sounds, and when it's not, and the hardware buttons are used, the RINGER volume gets adjusted instead.

How do I set it up so, as long as the app is running, the user can adjust the playback volume?

Thanks!

+1  A: 

so you want to disable ringer playback volume as long as the app is running? therefore the hardware controls will only adjust the app playback sounds?

i dont think this is possible unless you are "always playing sound" for example, many games are always playing background music or what have you.

Keith Fitzgerald
+1  A: 

You might be able to accomplish this by constantly playing a 0 volume sound as long as your app is running. You could then play your sound clips over it.

Gordon Wilson
+4  A: 

Turns out this can be accomplished by allocating an AVAudioPlayer with any valid sound file and calling the prepareToPlay method, without ever calling the play method.

Works perfectly.

DanM
I think this solution is better than the one you accepted
hhafez
Yes, I am using this method. It works great.
Dana Holt
Reviving an old thread. But if I do this, none of my audio files play after that! I have some 20 files and am using a common AVAudioPlayer object to play them on user selection. On viewDidLoad I instantiated the player object with a sound file and called prepareToPlay. But after this if I instantiate the player object with any file and call play, no sound plays! Can you please help.
lostInTransit
This is assuming you're ONLY using this particular AVAudioPlayer object to sit there and make sure the volume buttons work properly. If you want to play any sound files at the same time, just allocate a new AVAudioPlayer; you can use that second one as a common player for the rest of your files.
DanM
+4  A: 

Start an AudioSession and don't stop it when you're not playing sounds.

Joachim Bengtsson