Estoy reproduciendo música con AVAudioPlayer en segundo plano. El problema es que si hay una llamada entrante interrumpe al reproductor, nunca se reanudará a menos que cambie al primer plano y lo haga manualmente.Cómo reanudar AVAudioPlayer después de la interrupción en el fondo
El código es simple, para reproducirla en el fondo:
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
url = [[NSURL alloc] initFileURLWithPath:...];
audio_player = [[AVAudioPlayer alloc] initWithContentsOfURL: url error:NULL];
audio_player.delegate = self;
bool ret = [audio_player play];
delegado para manejar las interrupciones:
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player
{
//tried this, not working [[AVAudioSession sharedInstance] setActive: NO error: nil];
NSLog(@"-- interrupted --");
}
//----------- THIS PART NOT WORKING WHEN RUNNING IN BACKGROUND ----------
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player
{
NSLog(@"resume!");
//--- tried, not working: [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
//--- tried, not working: [[AVAudioSession sharedInstance] setActive: YES error: nil];
//--- tried, not working: [audio_player prepareToPlay];
[audio_player play];
}
¿Puede cualquiera que me ayude?
Mismo pb, ¿encontró una solución? – fvisticot
hasta ahora, no. pero hay una solución. Las aplicaciones de apple store de ejemplo lo han hecho. – Paul