Search code examples
iosobjective-cavaudioplayer

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.


Solution

  • 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;
    }];
    }