Search code examples
androidaudiospotifyexoplayeramazon-fire-tv

3rd party music apps launch when pressing play/pause on my app on FireTV


On the newest FireTV OS for the Fire Stick Lite 2020 I noticed that when we play a third party app like Spotify for example music keeps playing when we press the home button. This is normal behavior, however when I launch my app I request the audio focus using the AudioManager and OnAudioFocusChangeListener (because I'm also playing music and don't want it to be noisy) so the 3rd party music stops playing. However, when I press play on the FireTV to control my media(Using ExoPlayer) it pauses my app, takes me back to the Spotify app and I lose focus of my own application.

Youtube and Twitch handle this well, so I was wondering if there is anything I am missing or any documentation I should refer to.

Any help is appreciated.


Solution

  • Found the answer. Seems like I wasn't Media Session... According to https://developer.android.com/guide/topics/media-apps/working-with-a-media-session

    We would need to use Media Session to tell the System that there is a media session happening in your app and each time you tell the system that your player is active or playing then your application would have priority over the media controllers on the remote and no other application can access it unless you state that your media session is no longer active.

    This helped too! https://developer.android.com/codelabs/supporting-mediasession

    Hope this helps anyone else!