我有一个ios应用程序,它在移动到后台时继续播放音乐。现在,如果有电话回答与否,应用程序不会继续播放音乐。 两天来,我一直在这里阅读有关这个问题的帖子。没有一个解决了我的问题。恢复通话后在后台运行的应用程序ios
我在使用AVQueuePlayer对象时,也会在需要时流式播放我的音乐。 现在委托方法已被弃用,因为ios6。所以我使用Notications。
令人惊奇的是,中断结束(电话呼叫结束)的通知,播放音乐也是写代码,但应用程序强制犯规播放音乐,直到它涉及到前台(与另一个通知)
这里是我的代码
-(void)viewWillAppear
{.....
........
.....
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioInterruptionNotification:) name:AVAudioSessionInterruptionNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioInterruptionNotification:) name:UIApplicationDidBecomeActiveNotification object:nil]
}
-(void)audioInterruptionNotification:(NSNotification *) aNotification {
NSLog(@"Interrupt %@", aNotification);
NSDictionary *dict = [aNotification userInfo];
NSUInteger typeKey = [[dict objectForKey:@"AVAudioSessionInterruptionTypeKey"] unsignedIntegerValue]; NSLog(@"%d", typeKey);
if (typeKey == 0)
{
[avPlayer play];
NSLog(@"1.......");
}
else if (typeKey == 1)
{
[avPlayer play];
NSLog(@"3...............");
;
}
}
而且,我已经试图通过调度队列引起的延迟。 委托方法似乎不起作用。 但是gaana,saavn和苹果的官方音乐应用程序在通话后恢复。所以这是可能的。 我似乎错过了某些东西。 如果我使用核心电话。我将不得不添加整个框架,这将增加应用程序的大小。 如果这是唯一的方式,请告诉我们如何。
谢谢,我真的很感激你的时间。
你使用过'UIApplicationWillEnterForegroundNotification'吗?请参阅https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/c/data/UIApplicationWillEnterForegroundNotification –
为什么前景通知会被解雇?我的应用程序从非活动状态转换为背景状不过谢谢你。 –