Media playback the right way (Big Android BBQ 2015)
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about Android media playback, such as media button receivers, lock screen controls, audio focus and MediaStyle notifications.
Recommended by 6 people across 7 different months, 2016 to 2019.
What it is
A 45-minute talk from Big Android BBQ 2015 by Google developer advocate Ian Lake on building Android media apps the right way. It covers using the Support Library's MediaSession, MediaStyle notifications, audio focus and media button handling to integrate with Bluetooth controls, lockscreens and Android Wear.
What people said
Strong rec Denis Pisarev · 2016-08 · Stack Overflow · on “continue playing the music when screen goes off”
I've learned all about AudioFocus and it's handling from these sources: Media playback the right way (Big Android BBQ 2015) [this video] How to properly handle audio interruptions [LINK] Managing Audio Focus [LINK] AudioManager [LINK] AudioManager.OnAudioFocusChangeListener [LINK] And, in a makeweight, here you have some info about cleaning up media resourses for your app to not to eat a bunch of memory and release media codec for other apps in case they want to use it too: Releasing the MediaPlayer [LINK] Cleaning up MediaPlayer resources [LINK]
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: [LINK] [this video] Also take a look at an example Android Music Player Sample [LINK]
Recommends ianhanniballake · 2016-01 · Stack Overflow · on “Receiving media key events in Service”
There's a few things in the MediaButtonReceiver documentation [LINK] you are missing firstly: You need to add the <intent-filter> for android.intent.action.MEDIA_BUTTON to your .myService - without this, MediaButtonReceiver won't know which Service to forward media buttons to You need to call handleIntent() [LINK] in your onStartCommand() [LINK] After that, your Service will be set up correctly, but you still won't receive media buttons. As explained in the Media Playback the Right Way talk [this video] , you need to become the preferred media button receiver by calling mediaSessionCompat.setActive(true) [LINK] . You'll also want to make sure you are calling mediaSessionCompat.setFlags(MediaSessi
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 [this video] , you must be registered as the 'preferred media app'. This is much easier when you use MediaSessionCompat [LINK] as explained in the MediaSessionCompat video [LINK] : 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 ianhanniballake · 2016-04 · Stack Overflow · on “Dismissing MediaStyle notifications”
@jasonhudgins - you're absolutely right and I cover that in my Media Playback the right way talk [this video] - note there are some caveats that the `NotificationCompat.MediaStyle` work around for versions prior to Lollipop.
Recommends James Oanta · 2017-03 · Stack Overflow · on “How do I properly create a Music Service class and link it to other activities?”
Problem 1. You can't bind a service to multiple activities in android. Problem 2. You will need a MediaController for that.Have a look here : [LINK] For the first problem, you can create an Application class to which you will bind the service too. The application class will live as long as your app, while your activities will change, therefore you won't be able to bind it to one single activity. Have a look here : [LINK] For the second one, please have a look on the Google samples provided by them. The media player sample is here : [LINK] A good starting point with the android Media Player is here : [this video]
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 [LINK] then go through with it [this video]
Recommends Jerryq27 · 2019-12 · Stack Overflow · on “MediaControllerCompat's getMetadata returns null”
I'm trying to make a audio app in Android using this [this video] video as a guide, and I'm having trouble with creating the notification using the audio's metadata. Here is the code I use to extract the audio files from the device: public void loadData() { ContentResolver contentResolver = context.getContentResolver(); String selection = Media.IS_MUSIC + "!= 0"; String[] projection = { Media._ID, Media.ARTIST, Media.TITLE, Media.DISPLAY_NAME, Media.DURATION, Media.ALBUM }; Cursor cursor = contentResolver.query( Media.EXTERNAL_CONTENT_URI, projection, selection, null, null ); if(cursor == null || !cursor.moveToFirst()) return; else { int size = cursor.getCount(); metadata = new ArrayList<>(size);
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
Cites Steve M · 2017-01 · Stack Overflow · on “App does not become the preferred MediaButtonReceiver when calling setActive(true) a second time”
I have tried to implement media button control per Google's talk [this video] I set the receiver in manifest: <receiver android:name="android.support.v4.media.session.MediaButtonReceiver"> <intent-filter> <action android:name="android.intent.action.MEDIA_BUTTON" /> </intent-filter> </receiver> <service android:name=".player.PlayFileService"> <intent-filter> <action android:name="android.intent.action.MEDIA_BUTTON" /> </intent-filter> </service> create the MediaSessionCompat in onCreate() of Service: mediaSession = new MediaSessionCompat(getApplicationContext(), "SOUNDPROCESS"); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS