AVPlayer not playing audio - iOS 9, Objective - C

后端 未结 2 396
名媛妹妹
名媛妹妹 2021-02-06 04:26

I am trying to play audio from a URL in my app. Everything happens as expected in iOS 8 (simulator and physical devices). For iOS 9, it works in simulator but on device, the aud

相关标签:
2条回答
  • 2021-02-06 04:58

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

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

    And some documentation

    0 讨论(0)
  • 2021-02-06 05:12

    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!

    0 讨论(0)
提交回复
热议问题