Create a simple MediaController that connects to a MediaBrowserService in order to test inter-app media controls.
This app works with the Universal Android Music Player sample, or any other app that implements the media APIs. https://github.com/googlesamples/android-UniversalMusicPlayer
PREPARE
and PLAY
buttons updates based on changes to
the media player state via onPlaybackStateChanged and onMetadataChanged and
includes the current player state reported via PlaybackStateCompat.getState().back
to return to the list of media apps.It's also possible to launch the app via ADB and the Activity manager (am).
Usage: adb shell am start mediacontroller://<package name>?[search|id|uri=<value>]
For example, to set up to play "Awakening" by Silent Partner in UAMP, the following command could be used:
adb shell am start "mediacontroller://com.example.android.uamp?id=__BY_GENRE__/Rock\|-1679589699"
Alternatively, it's possible to use extras to pass parameters, which is recommended when passing parameters that include URI-like components:
Extra names:
com.example.android.mediacontroller.PACKAGE_NAME
com.example.android.mediacontroller.SEARCH
com.example.android.mediacontroller.MEDIA_ID
com.example.android.mediacontroller.URI
Another example with UAMP is to perform a search with the term "jazz?" one would use:
adb shell am start -n com.example.android.mediacontroller/.MediaAppControllerActivity --es com.example.android.mediacontroller.PACKAGE_NAME "com.example.android.uamp" --es com.example.android.mediacontroller.SEARCH "jazz?"
This app allows for testing how media apps respond to audio focus changes.
The app allows requesting and abandoning the following types of audio focus:
For more information on audio focus please see Managing Audio Focus.
This tool displays the supported actions as reported by the MediaSession in the call to MediaSessionCompat.setPlaybackState() as a list of prepare and play actions on the main screen. For actions that are not declared as supported, it also colors the buttons red on the controller screen.
See the screenshots below for examples.
Copyright 2017 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
compileSdkVersion 25
applicationId "com.example.android.mediacontroller"
minSdkVersion 17
targetSdkVersion 25
versionCode 1
versionName "1.0"
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
package com.example.android.mediacontroller
App entry point. Presents a list of apps that implement a MediaBrowser interface (via a receiver that responds to the action "android.media.browse.MediaBrowserService").
Callback used by {@link FindMediaAppsTask}.
Click listener used by {@link MediaListAdapter}.
Finds installed packages that have registered a {@link android.service.media.MediaBrowserService} or {@link android.support.v4.media.MediaBrowserServiceCompat} service by looking for packages that have services that respond to the "android.media.browse.MediaBrowserService" action.
This class connects to a {@link android.support.v4.media.MediaBrowserServiceCompat} in order to get a {@link MediaControllerCompat}. Buttons are displayed on screen so that the user can exercise the {@link android.support.v4.media.session.MediaSessionCompat.Callback} methods of the media app.
Example: If you install the UAMP app and this Monkey Test app, you will be able to test UAMP media controls.
Builds an {@link Intent} to launch this Activity with a set of extras. * @param activity The Activity building the Intent. @param appDetails The app details about the media app to connect to. @return An Intent that can be used to start the Activity.
This updates the buttons on the controller view to show actions that aren't included in the declared supported actions in red to more easily detect potential bugs. * @param actions The mask of currently supported actions from {@see PlaybackStateCompat.getActions()}.
Helper class to manage audio focus requests and the UI surrounding this feature.
This list MUST match the order of the string-array {@see R.array.audio_focus_types}.