Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AudioServicesPlaySystemSound Volume on iPad

Tags:

ios

audio

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....

like image 407
Marg Avatar asked May 04 '12 12:05

Marg


1 Answers

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];
like image 157
NightCoder Avatar answered Nov 10 '22 05:11

NightCoder