Saltar al contenido
Skillpedia
Apps móviles10 mil · #11923

media3-cast-integration

Qué hace

Esta skill guía la adición de la reproducción con Google Cast a una app de Android con la biblioteca Media3. Cubre las dependencias, el manifiesto, las opciones de Cast y el reproductor para pantallas de Compose y de Views. Es para desarrolladores de Android que quieren compatibilidad con Cast o que pasan desde el SDK antiguo de Cast.

Cuándo usarla

  • ✓Cuando quieres que los usuarios envíen vídeo o audio desde tu app de Android a una TV o a un altavoz.
  • ✓Cuando necesitas pasar una app del SDK heredado de Google Cast a Media3 Cast.
  • ✓Cuando quieres configurar el reproductor de Cast y el proveedor de opciones en una app de Compose o de Views.

Link de la skill

https://github.com/android/skills/blob/main/media/media3-cast-integration/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/android/skills/blob/main/media/media3-cast-integration/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Añade Google Cast a mi app de vídeo de Android con Media3 para que los usuarios puedan enviar el contenido a su TV.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La skill comprueba que la versión de Media3 sea la 1.9.0 o superior y luego añade las dependencias y las entradas del manifiesto necesarias. Después configura las opciones de Cast y el reproductor de Cast para las pantallas de la app.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

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.1")
    
  • 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 : Sess

Preguntas frecuentes

¿Qué versión de Media3 necesita?

Media3 debe ser la versión 1.9.0 o superior, ya que Cast no está disponible en versiones anteriores.

¿Debo usar el SDK heredado de Cast?

No. La skill indica que el SDK heredado está en modo de mantenimiento, así que las configuraciones nuevas deberían usar Media3 Cast, salvo que pidas el SDK heredado.

¿Funciona con Compose y con Views?

Sí. Cubre la reproducción con Cast tanto en pantallas de Compose como en pantallas basadas en Views.

Detalles

Descripción original del autor

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.

repo: android/skills

Popularidad

Estrellas en GitHub
10 mil
Posición en el ranking
#11923
Licencia
Apache-2.0
Actualizada
29/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas