Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually, you can do this. It is controlled via the Audio Session and has nothing to do with <code>AVAudioPlayer</code> itself. Why don't you want to use AudioSession? They play nice together...</p> <p>In your app, you should initialize the Audio Session, and then you can also tell indicate what kind of audio you intend to play. If you're a music player, then it sort of makes sense that the user would want to hear the audio <em>even with the ring/silent switch enabled</em>.</p> <pre><code> AudioSessionInitialize (NULL, NULL, NULL, NULL); AudioSessionSetActive(true); // Allow playback even if Ring/Silent switch is on mute UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback; AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&amp;sessionCategory); </code></pre> <p>I have an app that I do this very thing, and use AVAudioPlayer to play audio, and with the ring/silent switch enabled, I can hear the audio.</p> <p><strong>UPDATE (11/6/2013)</strong></p> <p>In the app I mentioned above, where I used the code above successfully, I have (for some time) been using the following code instead to achieve the same result:</p> <pre> AVAudioSession *audioSession = [AVAudioSession sharedInstance]; NSError *error = nil; BOOL result = NO; if ([audioSession respondsToSelector:@selector(setActive:withOptions:error:)]) { result = [audioSession setActive:YES withOptions:0 error:&error]; // iOS6+ } else { [audioSession setActive:YES withFlags:0 error:&error]; // iOS5 and below } if (!result && error) { // deal with the error } error = nil; result = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&error]; if (!result && error) { // deal with the error } </pre> <p>I thought I'd post this as an alternative, in light of the most recent comment to this answer. :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload