AudioServicesPlaySystemSound Volume on iPad

in my application I use AudioServicesPlaySystemSound to play small caf files. When I launch my application on the iPhone and change the volume to the side buttons, the sound of the application changes too, but on the iPad the sound volume in my application is always the same. Maybe because on the iPhone the ringer volume, and on the iPad is the volume of the device.

How can I get the same iPhone behavior on an iPad?

Excuse me for my bad english ....

+8
ios audio
source share
1 answer

I had the same problem, but if you change the sound volume in the system using the buttons, all the sounds in the system will be changed along with your application. I found this very annoying. The solution is to use AVAudioPlayer instead of AudioServices: as easy, but more versatile. And there you can fine 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]; 
+5
source share

All Articles