Note that there are some explanatory texts on larger screens.

plurals
  1. POAVAudioPlayer stops playing on screen lock even though the category is AVAudioSessionCategoryPlayback
    text
    copied!<p>My app uses AVAudioPlayer to play through audio playlists. I haven't changed the code between iOS4.3 and iOS5. However, the audio on iOS5 pauses on a screen lock even though I've set the category to be AVAudioSessionCategoryPlayback.</p> <p>I've tested the code on iOS4.3 and iOS5 devices and this problem occurs on the iOS5 device.</p> <p>Has anyone else faced this problem? I'm at a loss since I don't even know where to start debugging this issue. My debugging started and ended with checking the AVAudioSessionCategory setting.</p> <p>The code where I'm doing it is:</p> <pre><code>[[AVAudioSession sharedInstance] setDelegate: self]; NSError *setCategoryError = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &amp;setCategoryError]; </code></pre> <p>Edit:</p> <p>I have already implemented and handled <code>audioPlayerBeginInterruption</code></p> <p>Edit #2: <strong>Solved</strong>! Thanks to <a href="https://stackoverflow.com/a/8087885/392178">Rhythmic Fistman's Answer</a></p> <p>Here's what was happening and what I did. iOS5 changes now push your app to the background even when the screen gets locked. This means that you need to enable background audio in your app, and make whatever view/viewcontroller handling that audio to be the first responder.</p> <p>Step 1: <a href="http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_background-audio/" rel="nofollow noreferrer">Enable background audio in your app</a></p> <p>Step 2: <a href="https://stackoverflow.com/questions/3196330/iphone-how-to-enable-ipod-controls-in-the-background-to-control-non-ipod-music">Enable remote events and become the first responder on the viewcontroller / view responsible for handling your audio playlist</a></p> <p><strong>NOTE: Make sure to test this on the device. The simulator will make it seem like the code did not work.</strong></p>
 

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