Search code examples
iosmpmovieplayercontroller

ios SystemSound will not respond to volume buttons


Ive used SystemSound in my app in order to play simple sound effects. In addition to this I play a musicvideo through the MPMoviePlayerController - now when I turn the volume up/down the music from the video responds as intended (lowering the volume up/down).

But the system sounds that are played does not respond to the volume. Im playing the system sounds when the user taps certain areas in the app. Heres a snippet of my code for that:

- (void)handleTap:(UITapGestureRecognizer *)recognizer {
   SystemSoundID completeSound = nil;

   //yellow folder in xcode doesnt need subdirectory param
   //blue folder (true folder) will need to use subdirectory:@"dirname"
   NSURL *sound_path  = [[NSBundle mainBundle] URLForResource: target_sound_filename withExtension: @"wav"];

   AudioServicesCreateSystemSoundID((__bridge CFURLRef)sound_path, &completeSound);
   AudioServicesPlaySystemSound(completeSound);
}

PS. I doublechecked that my "Settings->Sounds->Ringer and Alerts->Change With Buttons" is set to ON (as I read on some other SO answers that leaving this option OFF will cause systemsound to not respond to the volume buttons)

Further the reason for using systemsound is that it gave the most accurate and responsive results when playing multiple sounds (like in a game).

Id prefer to not use OpenAL if possible (even through 3rd party sound libraries like Finch or CocosDenshion)

Any ideas?


Solution

  • Use the AVAudioPlayer class for playing sounds that are controlled by the user's volume settings (non-system sounds).

    You can retain instances of AVAudioPlayer for each sound file that you use regularly and simply call the play method. Use prepareToPlay to preload the buffers.