使用AVPlayer 播放音频,ipad设置静音后声音 仍然播放,查资料后需要如下设置 :

1  func  setAudioCAtegory() {
2         let audioSession = AVAudioSession.sharedInstance()
3        audioSession.setCategory(AVAudioSessionCategorySoloAmbient);
4         // audioSession.setCategory(AVAudioSessionCategorySoloAmbient);
5         audioSession.setActive(true)  
6 
7     }

设置之后 报异常:

Call can throw, but it is not marked with \’try\’ and the error is not handled  

修改如下:

1     func  setAudioCAtegory() {
2         let audioSession = AVAudioSession.sharedInstance()
3         try! audioSession.setCategory(AVAudioSessionCategorySoloAmbient);
4         try! audioSession.setActive(true)
5 
6     }

参考链接:http://stackoverflow.com/questions/32312827/in-swift-how-do-i-let-other-apps-continue-to-play-audio-when-my-app-is-open

修改完成之后,我发现自己设置的画中画模式不支持了,最后发下 由于我在AppDelegate 中设置了

1 func setPiPAllow(){
2         let audiosession = AVAudioSession.sharedInstance()
3         do {
4             try audiosession.setCategory(AVAudioSessionCategoryPlayback)
5         }
6         catch {
7             print("Audio session setCategory failed")
8         }
9     }

又在播放器中再一次设置了AVAudioSession.sharedInstance,并且是不同的模式。导致画中画不支持,结论:目前画中画和 静音不能兼容,只能舍弃静音模式。

参考链接如下:http://www.cnblogs.com/kenshincui/p/4186022.html

版权声明:本文为741162830qq原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/741162830qq/p/4958687.html