skip to Main Content

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.

2

Answers


  1. 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: [])
    
    Login or Signup to reply.
  2. I don’t think you can’t overrule the hardware button (neither you should), a better approach would be to check if the device is silent and show an alert to the user in that case, BUT, as the below library says:

    There is no native iOS API to detect if the mute switch is
    enabled/disabled on a device.

    The general principle to check if the device is muted is to play a
    short sound and detect the length it took to play. From this length we
    can determine if it was muted or not.

    The library that may help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search