AVPlayer not playing audio - iOS 9, Objective - C

会有一股神秘感。 提交于 2019-12-03 08:12:06

After doing various trial and error tactics for over 5 days, I finally figured out that my problem was with the mute switch of the phone. When it is on mute, the audio does't play! So, I added the following line of code to specify my category as playback and now it plays even when my device switch is on mute

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

Thank you!

For anyone with this same issue, here is the Swift solution.

try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: [])

And some documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!