Understanding MediaSession (Part 1/4)

Is MediaSession for me?

Nazmul Idris (Naz)
Sep 3, 2017 · 2 min read

As an Android developer working with Media APIs, you might have heard about MediaSession. You might be curious about what it does, when to use it, and when not to.

Before going into the details you can use this flowchart to determine if your media playback app will greatly benefit from using it.

The goal of this series of articles is to give you a deep understanding of MediaSession, what it is good for, when to use it, and when not to. This is the first part of a 4 part series that includes:

  1. Is MediaSession for me? (this article)

Examples of media playback apps

Let’s go through a few types of apps you might be building to see if MediaSession is needed.

Video game app

Video games often include music and sound effects to enhance the user’s experience, but, in this case, the user usually doesn’t have any expectation of being able to pause the music or skip to the next track, so there would be no need to use a MediaSession here.

Video player app

A video player may only play audio and video while the app is in the foreground, so it may not seem necessary to integrate with MediaSession. However, in order for your app to respond to media button events you would need to integrate with MediaSession.

Music player app

A music player app should absolutely integrate MediaSession. MediaSession provides hooks for playback control via media buttons on headphones, Android Wear, Android Auto, and Google Assistant. It might also benefit from utilizing a MediaBrowserService. By providing a MediaBrowserService, the app can allow users to use Android Auto, Wear, Assistant, and Bluetooth devices to navigate the media contents (without using the app’s UI).

To learn more about what MediaSession is and isn’t and the larger context in which it fits in the Android ecosystem read the second article in this this series.

Android Media Resources

Android Developers

The official Android Developers publication on Medium

Android Developers

Articles on modern tools and resources to help you build experiences that people love, faster and easier, across every Android device.

Nazmul Idris (Naz)

Written by

Google SWE, entrepreneur, leader, designer, dancer, TaiChi'er, Yogi, racer, healer, storyteller. I ❤️ leadership, authenticity, empowerment, & lifelong learning

Android Developers

Articles on modern tools and resources to help you build experiences that people love, faster and easier, across every Android device.