media3-cast-integration

Implements Google Cast playback in Android apps using Jetpack Media3 CastPlayer.

7.1k|466|Updated Mar 16, 2026
One-click install
npx skills add https://github.com/android/skills --skill media3-cast-integration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: media3-cast-integration
Source: https://github.com/android/skills/tree/main/media/media3-cast-integration
Command: npx skills add https://github.com/android/skills --skill media3-cast-integration

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Adding Google Cast support to an Android media app involves coordinating build dependencies, manifest configuration, player architecture, and UI integration, and migrating from the legacy Cast SDK adds further risk of compilation errors and broken playback.

Core Features & Use Cases

  • Dependency and Manifest Setup: Adds the media3-cast dependency (version 1.9.0 or higher), declares the DefaultCastOptionsProvider, and ensures correct permissions.
  • Player Architecture: Initializes ExoPlayer and CastPlayer inside a MediaSessionService, with optional RemoteCastPlayer support and playback state transfer between local and remote devices.
  • UI Integration: Configures the MediaRouteButton composable for Compose UIs or MediaRouteButtonFactory for View-based UIs, including recomposition and rebinding on device changes.
  • Use Case: When migrating an app from the legacy Google Cast SDK to Jetpack Media3, this Skill guides replacing forwarding player wrappers with CastPlayer while keeping legacy code intact until cleanup is explicitly requested.

Quick Start

Add Google Cast support to my Android media app using Jetpack Media3 CastPlayer.

Frequently Asked Questions about media3-cast-integration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add Google Cast to an Android app with Media3?

Add the androidx.media3:media3-cast dependency (1.9.0+), declare DefaultCastOptionsProvider in your manifest, then build a CastPlayer with ExoPlayer as the local player inside a MediaSessionService and pass it to MediaSession.Builder.

How to migrate from legacy Cast SDK to Media3 CastPlayer?

Add Media3 Cast dependencies first while keeping legacy dependencies to avoid compilation errors, replace forwarding player wrappers with CastPlayer, and swap CastButtonFactory for MediaRouteButtonFactory. Remove legacy files only when explicitly requested.

What is the difference between CastPlayer and RemoteCastPlayer?

CastPlayer manages both local and remote playback and is the default choice. RemoteCastPlayer only handles remote playback and requires a SessionAvailabilityListener to transfer playback state between the local ExoPlayer and the Cast session.

Does Media3 Cast work with Jetpack Compose?

Yes, Media3 Cast provides a MediaRouteButton composable in the androidx.media3.cast package for Compose UIs. You should use the Material3 Player composable instead of PlayerSurface and force recomposition on DeviceInfo changes.

Why does my PlayerView show a black screen after switching to Cast?

PlayerView does not rebind the video surface when playback moves between local and remote devices. Fix it by listening for onDeviceInfoChanged and resetting playerView.player to null before reassigning the controller.

What minimum Media3 version is required for Cast support?

Jetpack Media3 version 1.9.0 or higher is required because Cast is not available in lower versions. All Media3 dependencies such as media3-exoplayer, media3-session, and media3-cast must use the same version.