Media3 Cast Integration logo

Media3 Cast Integration

OrganizationPopular
android
media3-cast-integration

Implements Google Cast support in Android apps using Jetpack Media3. Handles adding build dependencies, updating manifest, configuring OptionsProvider, and managing CastPlayer or RemoteCastPlayer for playback in both Compose and View-based UIs. Use when adding Cast functionality or migrating from legacy Cast SDK to Media3 Cast.

Overview

Publisherandroid
Repositoryskills
Skill namemedia3-cast-integration
Stars
7.4K
Forks
484
Bundled files
3
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by android on GitHub. Read the source before you install it.

Installation

Install the Media3 Cast Integration AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/android/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/media/media3-cast-integration .claude/skills/media3-cast-integration
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Media3 Cast Integration in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Media3 Cast Integration on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Media3 Cast Integration is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Prerequisites

  • Jetpack Media3 version must be >= 1.9.0. Cast isn't available in lower versions.

Glossary

  • CastPlayer : Media3 Player that controls playback on both local and remote Cast devices.
  • RemoteCastPlayer : Media3 Player that communicates with a Cast receiver, only used for remote playback.
  • Google Cast SDK: Legacy casting SDK in maintenance mode, superseded by Jetpack Media3.
  • OptionsProvider : Interface providing configuration options to initialize GMS CastContext.

Common guidelines

Step 1: Set up dependencies

To complete this step, you MUST ensure the following:

  • In the app-level build file, declare the media3-cast dependency version 1.9.0 or higher.

    implementation("androidx.media3:media3-cast:1.11.0")
  • Ensure required Media3 dependencies are present:

    • androidx.media3:media3-exoplayer
    • androidx.media3:media3-session
    • androidx.media3:media3-ui-compose
  • If the application uses legacy Views, add media3-ui.

  • Enforce the same versions across all Media3 dependencies.

  • Use configurations in "Add build dependencies" section of Getting started with CastPlayer as the source of truth.

  • For apps without an existing Cast integration:

    • Verify legacy Cast SDK (libs.play.services.cast.framework) is absent.
  • If Migrating from Legacy Cast SDK:

    • Add Media3 Cast dependencies first.
    • Keep existing legacy dependencies untouched at this stage to prevent compilation errors.

Step 2: Update the manifest

To complete this step, you MUST ensure the following:

  • Inside the manifest's <application> tag, declare the Cast options provider.
  • Use DefaultCastOptionsProvider by default. See the "OptionsProvider" section in Getting started with CastPlayer.
  • Declare a custom OptionsProvider only if explicitly requested. See Customize CastOptions.
  • Ensure INTERNET permission is present. Don't add any unnecessary permissions.
  • If Migrating from Legacy Cast SDK:
    • Don't delete existing custom options provider files or manifest entries.

Step 3: Implement the player and service

Architecture baseline

Before integrating Media3 Cast, an existing app follows one of two setups:

  • Local-only playback: Uses Media3 ExoPlayer only to support local playback.
  • Legacy Cast setup: Uses ExoPlayer for local playback, alongside a Player wrapper over the legacy RemoteMediaClient for remote playback. The UI interfaces with a MediaSession interacting with a ForwardingPlayer, which finally routes controls to either local or remote playback.

To complete this step, you MUST ensure the following:

  • Inside the application's MediaSessionService (or MediaLibraryService) onCreate() method, initialize ExoPlayer and CastPlayer.
  • Use CastPlayer by default unless RemoteCastPlayer is explicitly requested. See the "Build a CastPlayer" section in Getting started with CastPlayer.
  • For CastPlayer, pass the instance directly to MediaSession.Builder.
  • Replace all legacy forwarding player wrappers.
  • Don't delete legacy class files yet to prevent compilation errors during migration.

Advanced: RemoteCastPlayer

  • Use RemoteCastPlayer only if explicitly requested by user.

  • Initialize MediaSession with localPlayer and set a SessionAvailabilityListener on RemoteCastPlayer to transfer playback state on Cast session availability changes:

    class PlaybackService : MediaSessionService() { private var mediaSession: MediaSession? = null private lateinit var localPlayer: ExoPlayer private lateinit var remotePlayer: RemoteCastPlayer

    override fun onCreate() {
      super.onCreate()
    
      localPlayer = ExoPlayer.Builder(this).build()
      remotePlayer = RemoteCastPlayer.Builder(this).build()
      mediaSession = MediaSession.Builder(this, localPlayer).build()
    
      remotePlayer.setSessionAvailabilityListener(
        object : SessionAvailabilityListener {
          override fun onCastSessionAvailable() {
            transferPlaybackState(localPlayer, remotePlayer)
          }
    
          override fun onCastSessionUnavailable() {
            transferPlaybackState(remotePlayer, localPlayer)
          }
        }
      )
    }
    
    private fun transferPlaybackState(previousPlayer: Player, newPlayer: Player) {
      if (previousPlayer.mediaItemCount > 0) {
        val transferStateBuilder = PlayerTransferState.builderFromPlayer(previousPlayer)
        if (previousPlayer.playbackState == Player.STATE_ENDED ||
            previousPlayer.currentPosition == C.TIME_END_OF_SOURCE) {
          transferStateBuilder.setCurrentMediaItemIndex(0)
          transferStateBuilder.setCurrentPosition(0)
        }
        transferStateBuilder.build().setToPlayer(newPlayer)
      }
    
      previousPlayer.stop()
      previousPlayer.clearMediaItems()
      newPlayer.prepare()
      mediaSession?.setPlayer(newPlayer)
    }

    }

Step 4: Set up the UI

Compose-based UI

To complete this step, you MUST ensure the following:

  • See the "Add a MediaRouteButton Composable to the Player" section in Getting started with CastPlayer for Compose integration guidelines.

  • Use the MediaRouteButton composable from androidx.media3.cast package.

  • Don't use AndroidView in the Compose UI hierarchy.

  • Place MediaRouteButton in an area next to playback controls. Don't hide it behind system UI.

  • Don't use PlayerSurface for custom player UI. Use the Material3 Player composable.

  • Force recomposition on playback location shifts to ensure UI sync. Use key constraints on DeviceInfo changes:

    @OptIn(UnstableApi::class)
    @Composable
    fun MainScreen() {
       val player = rememberMediaController()
       val deviceInfo = rememberDeviceInfo(player)
       player?.let { activePlayer -> key(deviceInfo) { PlayerScreen(player = activePlayer) } }
    }
    
    @Composable
    private fun rememberMediaController(): Player? {
       // Logic to connect MediaController to MediaSession and release it
    }
    
    @Composable
    private fun rememberDeviceInfo(player: Player?): DeviceInfo? {
       var deviceInfo by remember(player) { mutableStateOf(player?.deviceInfo) }
       DisposableEffect(player) {
           val activePlayer = player ?: return@DisposableEffect onDispose {}
           deviceInfo = activePlayer.deviceInfo
           val listener = object : Player.Listener {
               override fun onDeviceInfoChanged(info: DeviceInfo) {
                   deviceInfo = info
               }
           }
          activePlayer.addListener(listener)
          onDispose { activePlayer.removeListener(listener) }
       }
       return deviceInfo
    }

View-based UI

To complete this step, you MUST ensure the following:

  • For View-based UI setups, see the "Add UI elements" section in Getting started with CastPlayer.

  • Casting Activities must extend AppCompatActivity or FragmentActivity and use a Theme.AppCompat descendant.

  • Ensure the AppCompat theme has a visible ActionBar if adding MediaRouteButton to the options menu.

  • Replace all instances and imports of CastButtonFactory with MediaRouteButtonFactory.

  • Rebind PlayerView.player references upon onDeviceInfoChanged events to prevent black screens or UI freezes:

    private val playerListener: Player.Listener =
      object : Player.Listener {
        override fun onDeviceInfoChanged(deviceInfo: DeviceInfo) {
          // Resetting to null bypasses PlayerView.setPlayer()'s instance equality check
          // (this.player == player), forcing it to re-bind the video surface to the controller.
          playerView.player = null
          playerView.player = controller
        }
      }
  • Migration to Compose:

Step 5: Clean up legacy Cast SDK code

[!WARNING] Warning: Don't perform cleanup directly. Remove legacy files and dependencies only when explicitly requested by the user.

To complete this step, you MUST ensure the following:

  • Remove legacy GMS Cast SDK (libs.play.services.cast.framework) and MediaRouter (libs.androidx.mediarouter) dependencies.
  • Delete custom OptionsProvider classes and manifest entries if DefaultCastOptionsProvider is adopted.
  • Remove legacy MediaTransferReceiver manifest declarations if present.
  • Remove all references to legacy Cast SDK components such as legacy helper wrappers, forwarding players, and RemoteMediaClient interfaces.
  • Delete legacy View XML layouts, menu files, and references to PlayerView if the migration to Compose is complete.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Media3 Cast Integration AI skill do?

Implements Google Cast support in Android apps using Jetpack Media3. Handles adding build dependencies, updating manifest, configuring OptionsProvider, and managing CastPlayer or RemoteCastPlayer for playback in both Compose and View-based UIs. Use when adding Cast functionality or migrating from legacy Cast SDK to Media3 Cast.

Why use Media3 Cast Integration on TypingMind?

Because you install it once and use it with any model. Media3 Cast Integration is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Media3 Cast Integration in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/android/skills/tree/main/media/media3-cast-integration. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Media3 Cast Integration?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Media3 Cast Integration?

As many as you like. As long as a model supports skills, you can use Media3 Cast Integration with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Media3 Cast Integration AI skill free?

Yes. It is published on GitHub by android under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇