1

What is the "correct" way to get my app to play audio even if the user's silent/mute switch is set to silent/vibrate?

Some background: I actually got it working in debug stage, but when I submitted my app to Apple and then later downloaded it from the app store, the audio was disabled in silent mode! Here is how I got it working in debug stage:

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                        sizeof(sessionCategory), &sessionCategory);

Audio was played using:

NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"];  
AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];  
theAudio.delegate = self;
[theAudio play];
user1221973
  • 21
  • 1
  • 4
  • Why do you want the app to play sounds when the user doesn't want to hear them? Are you sure this is something your users want? – Hyperbole Mar 28 '12 at 20:25
  • I know there's the rule about "you shouldn't play audio in silent mode it's a bad user experience," but my app is kind of an exception because the sole purpose of it is to make sounds, and the "bad user experience" would actually come from users hitting "play," expecting to hear sounds, and instead getting nothing, not realizing that their silent switch is set to silent. – user1221973 Mar 28 '12 at 21:11
  • Perhaps detect the mute state and inform the user that they won't hear sounds until they un-mute their device. That's more in-line with Apple's HIG anyway. – Hyperbole Mar 28 '12 at 21:12
  • @Hyperbole This is a great idea, thanks for your suggestion. – user1221973 Mar 28 '12 at 21:29

1 Answers1

0

I think it does the same thing, but have you tried, setting the setting throught AVFoundation like so?

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];
Daniel
  • 22,363
  • 9
  • 64
  • 71