I have problem with AVAudioPlayer in iphone when ever the my ipod is lock(sleep) the song is stop.What I have do in coding for making music is c开发者_如何学Pythonontinueslu start even the ipod is lock(sleep) . please help me
I am totally new in this .
You can use different categories to do this:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
...
// allows you to play when the screen is locked and also when the ringer is set to silent
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
...
}
If you want to continue to play the sound on iOS4 when your app gets suspended into the background (for instance, the user hits the home button), then you also need to add this to your info.plist
file (this shows it in plain text mode):
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
By the way, if you ever really needed to handle an interruption like your question title said (like a phone call, etc), there is a delegate method for that in the AVAudioPlayer
class:
- (void) audioPlayerBeginInterruption: (AVAudioPlayer *) player { }
and
- (void) audioPlayerEndInterruption: (AVAudioPlayer *) player { }
精彩评论