1

We're using the below code and calling this code many times through the app to play the button and application sounds. Currently we're having an issue where the volume controls on the device do not change the internal application volume. We can turn the volume all the way to off and the application will still play sounds. Is there a way to detect when the hardware volume controls have been changes and update the sound volume accordingly? We don't want to update sliders simply make the audio session respond to the newly set volume. Thank you very much in advance.

AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 category = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                        sizeof(category),
                        &category);
AudioSessionSetActive(YES);

NSString *path = [NSString stringWithFormat:@"%@/%@.wav",
                                            [[NSBundle mainBundle] resourcePath],
                                            sound];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
danh
  • 62,181
  • 10
  • 95
  • 136
mejim707
  • 431
  • 3
  • 16

1 Answers1

0

I have already done R&D on the same issue, you can change volume slider by changing the external device volume by using

MPMusicPlayerController *_musicController = [MPMusicPlayerController iPodMusicPlayer];

Below there are few links perhaps these help you.

  1. http://stackoverflow.com/questions/9227435/changing-device-volume

  2. http://oleb.net/blog/2009/07/the-music-player-framework-in-the-iphone-sdk/

Khalid Usman
  • 1,272
  • 1
  • 13
  • 32
  • We are actually having an issue where the external hardware volume controls do not alter the volume in the app after the app is loaded. So, if the app loads, and you can hear sounds you can turn the sound down but the sounds in the app remains loud. Is there something with the audio session that I need to enable to allow the hardware buttons to alter the sound of the audio session? It is a rather strange issue. Thanks – mejim707 Apr 26 '12 at 18:51
  • Any progress for this? I also encounter the same problem now. thank you – vietstone Mar 12 '14 at 08:09