如何恢复出来后,会电话(IOS)的背景音乐? [英] How to resume background music after out-going phone call (iOS)?

查看:395
本文介绍了如何恢复出来后,会电话(IOS)的背景音乐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(支持后台)。我的问题是,如果我想打电话给别人,而我在听音乐,如何调用后恢复它?我已经实现了AVAudioPlayer的委托方法:

I'm using AVAudioPlayer to play music (background supported). My question is if I want to call somebody while I'm listening to the music, how to resume it after the call? I've implement the AVAudioPlayer's delegate method:

- (void)audioPlayerEndInterruption:(AVAudioPlayer *)thePlayer {
    [[AVAudioSession sharedInstance] setActive:YES error:nil];
    [self.player play];
}

,但这将不会允许音乐继续

but this will not allow the music to continue.

我也试过用AVAudioSessionDelegate方法(只是一种尝试):

I've also tried to use the AVAudioSessionDelegate method (just a try):

- (void)viewDidLoad {
    [[AVAudioSession sharedInstance] setDelegate:self];
}

- (void)endInterruption
{
    [[AVAudioSession sharedInstance] setActive:YES error:nil];
    [self.player play];
}

但再次,这将不会导致音乐恢复。关于如何解决这个问题的任何想法?

but again this won't cause the music to resume. Any ideas about how to solve this problem?

推荐答案

您可以恢复它。完成你的音频会话后,必须通知其它应用程序,我的应用程序关闭音频会话,你可以利用它。使用以下code。

You can resume it. After finishing your audio session you have to notify other app that my app deactivate the audio session and you can make use of it. Use the following code.

[[AVAudioSession sharedInstance] setActive:NO withFlags:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];

这篇关于如何恢复出来后,会电话(IOS)的背景音乐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆