简历背景音频播放声音AVAudioPlayer后 [英] Resume Background Audio After Playing Sound With AVAudioPlayer

查看:320
本文介绍了简历背景音频播放声音AVAudioPlayer后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来恢复被其他应用程序播放的音频我的应用程序播放自己的声音AVAudioPlayer后。现在,如果我听音乐并启动我的应用程序,它会暂停音乐,播放我的声音,但无法恢复的背景音乐。

下面是我在做什么,产生的声音回放:

  myChime = [[AVAudioPlayer页头] initWithContentsOfURL:[NSURL fileURLWithPath:[一个NSBundle mainBundle] pathForResource:@磬ofType:@MP3]]错误:无];
myChime.delegate =自我;
[myChime播放];
//在这里,我希望恢复该系统被打之前,我的应用程序发挥它的声音声音。我看过很多应用程序做到这一点如说话声音的方向,然后恢复音乐,GPS应用程序。


解决方案

您需要正确地贯彻落实 AVAudioSession 委托方法。如果设置了音频会话为无效,那么系统就会知道你做你的演奏声将恢复任何其他音频会议。请参阅<一个href=\"http://developer.apple.com/library/IOS/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007875\">Audio会话编程指南,尤其是 SETACTIVE:错误:

I am looking for a way to resume audio played by another application after my application plays its own sound with AVAudioPlayer. Right now, if I am listening to music and launch my application, it pauses the music, plays my sound, but doesn't resume the background music.

Here is what i'm doing to generate the sound playback:

myChime = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"chime" ofType:@"mp3"]] error:nil];
myChime.delegate = self;
[myChime play];
// Here I am looking to resume the audio that the system was playing before my application played its sound.  I have seen many applications do this such as, GPS apps that speak a voice direction and then resume the music.

解决方案

You need to properly implement the AVAudioSession delegate methods. If you set the audio session to inactive, then the system will know you are done playing your sound and will resume any other audio sessions. Refer to the Audio Session Programming Guide, especially the setActive:error: method.

这篇关于简历背景音频播放声音AVAudioPlayer后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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