Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone (SDK 2.2): adusting playback volume while NOT actively playing music w/ AVFoundation?

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!

like image 444
DanM Avatar asked Dec 22 '22 13:12

DanM


2 Answers

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.

like image 114
DanM Avatar answered Dec 28 '22 07:12

DanM


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

like image 33
nevyn Avatar answered Dec 28 '22 07:12

nevyn