Search code examples
iosswiftavqueueplayer

Play sounds with AVQueuePlayer even if iPhone is muted


I'm using AVQueuePlayer to play sounds (a little App for kids to listen illustrated books), but if iPhone is muted the audio isn't audible.

There is a way to force audio even if iPhone is muted? I think to YouTube where audio is audible or Instagram when you have to pop up the volume to listen stories.

Thanks.


Solution

  • By default AVPlayer is dependent on ringer position if the ringer is in silent mode you can't listen to audio. if you want to play audio even the ringer is in silent position then set setCategory as AVAudioSessionCategoryPlayback before playing video.

    try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, options: [])