Search code examples
objective-ciosaudioavplayerringtone

How can I prevent my application (using AVPlayer) is muted when the ringtone is muted?


The topic may sound strange, but please keep reading on.

I am using AVPlayer to play some sound from the iPod library and everything works fine when using it with headphones plugged in, but when I want to use the app to play from the built in speakers there is no sound output. (The time counter and everything else in the application is still working like there would be sound output. Like it is just muted.)

I checked the volume and the mute lock and then found out that the ringtone was muted. But ringtone muting doesn't affect other applications like the iPod app itself or the Spotify music app.

How can I prevent my application (using AVPlayer) is muted when the ringtone is muted and behave like other music player apps?


Solution

  • You should set your app's audio session to AVAudioSessionCategoryPlayback. From the docs:

    Use this category for an application whose audio playback is of primary importance. Your audio plays even with the screen locked and with the Ring/Silent switch set to silent.