SBM SBM - 4 months ago 11
iOS Question

AVAudioPlayer doesn't play audio after the home button is pressed

I'm new in ios development.I'm using AVAudioPlayer.The audio plays in foreground. After that when i tapped the home button the app comes to background but the audio was muted.

Answer

Try this,

- (void)applicationDidEnterBackground:(UIApplication *)application
 {
__block UIBackgroundTaskIdentifier task = 0;
task=[application beginBackgroundTaskWithExpirationHandler:^{
    NSLog(@"Expiration handler called %f",[application backgroundTimeRemaining]);
    [application endBackgroundTask:task];
    task=UIBackgroundTaskInvalid;
}];
}
Comments