AVAudioPlayer在后台没有响应
当我的应用程序收到voip通知时,我在后台播放audio。 但AVAudioPlayerperformance怪异,有时会播放audio,有时并非没有任何错误。 多数民众赞成我是如何玩:
func playAudio() { // Set the sound file name & extension let alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("testAudio", ofType: "wav")!) // Play the sound do { try audioPlayer = AVAudioPlayer(contentsOfURL: alertSound) audioPlayer.delegate = self if (audioPlayer.prepareToPlay()) { audioPlayer.play() } else {NSLog("there is error")} } catch { NSLog("there is \(error)") } }
我在我的AppDelegate应用程序函数中初始化AVAudioSession:
do { audioPlayer = AVAudioPlayer() audioSession = AVAudioSession() try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: [AVAudioSessionCategoryOptions.MixWithOthers]) try audioSession.setActive(true) try audioSession.overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker) } catch { NSLog("there is \(error)") }
当然还有var audioPlayer: AVAudioPlayer!
作为一个类动词
它的工作一两分钟,然后AVAudioPlayer停止响应没有任何错误。 我甚至尝试使用AVAudioPlayerDelegate来接收事件,但没有发生。
有人可以解释这种行为吗? 这是在ios中的错误? 或者我做错了什么? 在Ios 9.2,iPhone 6设备,Xcode 7.2上testing。
谢谢。
- 获取iPhone连接的路由器的IP地址
- Monotouch中的子类化和重写UITextField
- CATransform3DROTATE与m34参数需要知道angular度以适应特定的高度
- 我怎么能张贴JSONstring到服务器
- 在C,Go和Swift中构建小型跨平台CLI工具
- UIAlertController自定义字体不适用于iOS
- 在iOS设备上找不到文件Qt Creator C ++ QStandardPaths :: standardLocations(QStandardPaths :: DownloadLo cation);
- 用贝塞尔曲线绘制弧
- 使用Xamarin从iPhone中的麦克风stream式传输audio