This post explains how to stop other application that plays music in background (Media player, Spotify, Deezer,…) and play audio from your app. Also, the second part explains how, when your audio stop playing, to release audio focus from your app and the audio apps in background to continue from where they stopped.

Get Audio Focus:

Get AudioManager System Service for providing access to volume and ringer mode control. Send a request to obtain the audio focus from the OS and to pause all background music.

Release Audio focus and continue background audio apps:

Stopping or pausing audio from app and releasing focus for other apps to play audio. It is abandoning audio focus listener (it is abandoning/setting to null)

 

The example implementation, have included API 26 and above support. API below 26 requestAudioFocus() is deprecated.

 

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *