Courtesy: GitHub

Media Controller Test

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.


  1. Select an app from the list of those presented.
    • Only apps that register a service with an intent filter action of "" will be shown.
  2. Select the type of action to perform to start the player. Options are:
    • Search: Sends the text provided as a search via prepareFromSearch() or playFromSearch().
    • Media ID: Sends the text provided as a media ID via prepareFromMediaId() or playFromMediaId().
    • URI: Sends the text provided as a URI via prepareFromUri() or playFromUri().
    • No Input: Calls the methods prepare() or play() directly.
  3. Text below the 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().
  4. Swipe to the left to see typical media controls with the media's art as a background, if provided.
  5. Press 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://\|-1679589699"

Alternatively, it's possible to use extras to pass parameters, which is recommended when passing parameters that include URI-like components:

Extra names:

  • Package name :
  • Search term :
  • Media ID :
  • URI :

Another example with UAMP is to perform a search with the term "jazz?" one would use:

adb shell am start -n --es "" --es "jazz?"


Audio Focus

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.

Supported Actions

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

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 ""

minSdkVersion 17

targetSdkVersion 25

versionCode 1

versionName "1.0"

compile fileTree(dir: 'libs', include: ['*.jar'])

compile ''

compile ''

compile ''

testCompile 'junit:junit:4.12'



App entry point. Presents a list of apps that implement a MediaBrowser interface (via a receiver that responds to the action "").

Callback used by {@link FindMediaAppsTask}.

Click listener used by {@link MediaListAdapter}.

Finds installed packages that have registered a {@link} or {@link} service by looking for packages that have services that respond to the "" action.


This class connects to a {@link} in order to get a {@link MediaControllerCompat}. Buttons are displayed on screen so that the user can exercise the {@link} 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}.