Media Playback with MediaSessionCompat (Android Development Patterns Ep 4)

Android Developers · 46K views · 2015 · 4:49

Open on YouTube

Software (other)Consumer devices & gadgetstutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the go-to explanation of MediaSessionCompat when answering questions about lock screen controls, Bluetooth media buttons and background media playback.

Recommended by 4 people across 4 different months, 2015 to 2017.

What it is

A short Android Developers video by Ian Lake, part of the Android Development Patterns series, explaining how MediaSessionCompat plugs a media app into the system. It covers media button handling, lock screen and notification controls, Android Wear, and using NotificationCompat.MediaStyle across API levels.

What people said

Recommends varunkr · 2015-09 · Stack Overflow · on “How to use MediaSessianCompat for Media playback?”

I have spent literally a whole day trying to understand how MediaSessionCompat works and what exactly it does? How is it different from MediaPlayer or AudioManager class? But to be honest I did not find any good explanation. The only info I got was from the android docs and some codes I found on the web which, according to me are not sufficient in this case. The only helpful thing was this [this video] video by Ian Lake that I found on Youtube. But I am still not able to understand how can we use it in our app. This is another code I found by Ian Lake, and I spent quite some time on it but still I have lots of doubts. package com.example.remotecontrolclient; import android.app.Service; import and

Recommends R00We · 2016-01 · Stack Overflow · on “How to add MediaPlayer controls on lock screen?”

Answer Juanjo outdated! Better to use MediaSessionCompat [LINK] which include in support library. Thank @ianhlake [LINK] for the good 2 video: [this video] [LINK] Also take a look at an example Android Music Player Sample [LINK]

Recommends ianhanniballake · 2016-03 · Stack Overflow · on “Android: How to control music service play/pause from bluetooth device?”

As explained in the Media playback the right way talk [LINK] , you must be registered as the 'preferred media app'. This is much easier when you use MediaSessionCompat [LINK] as explained in the MediaSessionCompat video [this video] : ComponentName mediaButtonReceiver = new ComponentName(context, YourBroadcastReceiver.class); MediaSessionCompat mediaSession = new MediaSessionCompat(context, tag, // Debugging tag, any string mediaButtonReceiver, null); mediaSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(this); // a MediaSessionCompat.Callback // This is what enables media buttons and should be called /

Recommends Dushyant Suthar · 2017-06 · Stack Overflow · on “how to prevent clashes of music player sound and background sound of my app in android studio”

It's kind of noobie question please go through with media player completely then after go through with MediaBrowserServiceCompat which was launched and presented by @ianhanniballake. You should read MediaPlayer as whole before implementing any part of it. If you would have gone through with it you might have had this very basic phenomenon noted in the documentation. Start with this first [this video] then go through with it [LINK]

Cites timothyjc · 2016-04 · Stack Overflow · on “How do you use MediaControllerCompat to control the current player?”

I asked Ian Lake, the Google dev who did the video on MediaSessionCompat, who said it is not possible ( [this video] ). We still have to use MediaSessionManager.

Cites Lee Hounshell · 2016-06 · Stack Overflow · on “Universal Android Media Player - UAMP”

I believe you need to modify the model/RemoteJSONSource.java so that it adds MediaMetadataCompat items into the tracks ArrayList. You will need to create a ' buildFromJSON ' method that creates a MediaMetadataCompat object. Be sure to set as many of the media attributes as possible. The Google example shows media being added from a remote JSON source. In my case, I have already loaded remote Firebase JSON into a local SQLite database. So I load my media from SQLite instead. To do that I modified the buildFromJson to be buildFromEpisodesCursor and changed the guts appropriately. (Firebase can send JSON updates to SQLite if the media changes.) Here is a snippet with the key codeblocks: public