in my application I use AudioServicesPlaySystemSound to play little caf files. When run my app on the iPhone and I change volume by lateral buttons, the app's sound changes too, but on iPad the sound's volume in my app is always the same. Maybe because on the iPhone is the ring volume, instead on the iPad is device volume.
How can I obtain same iPhone behavior on iPad?
Excuse me for my bad English....
I had the same problem but if you change the system sounds volume with buttons all the system sounds will be modified along with your app's. I found this really annoying. The solution is to use AVAudioPlayer in place of AudioServices: as easy, but way more versatile. And there you can finely tune the volume for each sound, programmatically.
NSURL *soundurl = [[NSBundle mainBundle] URLForResource: @"mysound" withExtension: @"caf"];
AVAudioPlayer *mySoundPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:soundurl error:&error];
mySoundPlayer .volume=0.4f; //between 0 and 1
[mySoundPlayer prepareToPlay];
mySoundPlayer.numberOfLoops=0; //or more if needed
[mySoundPlayer play];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With