Page Summary
-
Output Switcher is a Cast SDK feature starting with Android 13 that allows seamless switching of content playback between local devices (phone speaker, Bluetooth) and remote Cast-enabled devices.
-
The feature utilizes the
MediaRouterlibrary to facilitate content transfer across different device types. -
Key use cases for Output Switcher include switching from local to remote, remote to local, and remote to remote playback.
-
Apps need to implement specific steps like enabling the
MediaTransferReceiverand handlingSessionManagerListenerandSessionTransferCallbackcallbacks to support these transitions. -
Remote-to-remote streaming expansion for audio apps is automatically supported by the Cast platform and can be tested through the Output Switcher UI.
Output Switcher is a feature of the Cast SDK that enables seamless transferring
between local and remote playback of content starting with Android 13. The goal
is to help sender apps easily and quickly control where the content is playing.
Output Switcher uses the
MediaRouter library to
switch the content playback among the phone speaker, paired Bluetooth devices,
and remote Cast-enabled devices. Use cases can be broken down into the following
scenarios:
Download and use the CastVideos-android sample app for reference on how to implement Output Switcher in your app.
Output Switcher should be enabled to support local-to-remote, remote-to-local and remote-to-remote using the steps covered in this guide. There are no additional steps needed to support the transfer between the local device speakers and paired Bluetooth devices.
Output Switcher UI
The Output Switcher displays the local and remote devices that are available as well as the current device states, including if the device is selected, is connecting, the current volume level. If there are other devices in addition to the current device, clicking other device lets you transfer the media playback to the selected device.

Known issues
- Media Sessions created for local playback will be dismissed and recreated when switching to the Cast SDK notification.
Entry points
Media notification
If an app posts a media notification with
MediaSession for
local playback (playing locally), the top-right corner of the media notification
displays a notification chip with the device name (such as phone speaker) that
the content is currently being played on. Tapping on the notification chip opens
the Output Switcher dialog system UI.

Volume settings
The Output Switcher dialog system UI can also be triggered by clicking the physical volume buttons on the device, tapping the settings icon at the bottom, and tapping the "Play <App Name> on <Cast Device>" text.

Summary of steps
- Ensure prerequisites are met
- Enable Output Switcher in AndroidManifest.xml
- Update SessionManagerListener for background casting
- Add support for Remote-to-Remote
- Set the setRemoteToLocalEnabled flag
- Continue playback locally
Prerequisites
- Migrate your existing Android app to AndroidX.
- Update your app's
build.gradleto use the minimum required version of the Android Sender SDK for the Output Switcher:dependencies { ... implementation 'com.google.android.gms:play-services-cast-framework:21.2.0' ... }
- App supports media notifications.
- Device running Android 13.
Set up Media Notifications
To use the Output Switcher,
audio and
video apps
are required to create a media notification to display the playback status and
controls for their media for local playback. This requires creating a
MediaSession,
setting the
MediaStyle
with the MediaSession's token, and setting the media controls on the
notification.
If you are not currently using a MediaStyle and MediaSession, the snippet
below shows how to set them up and guides are available for setting up the media
session callbacks for
audio and
video
apps:
// Create a media session. NotificationCompat.MediaStyle // PlayerService is your own Service or Activity responsible for media playback. val mediaSession = MediaSessionCompat(this, "PlayerService") // Create a MediaStyle object and supply your media session token to it. val mediaStyle = Notification.MediaStyle().setMediaSession(mediaSession.sessionToken) // Create a Notification which is styled by your MediaStyle object. // This connects your media session to the media controls. // Don't forget to include a small icon. val notification