Pular para o conteúdo
Skillpedia
Apps de celular10 mil · #11923

media3-cast-integration

O que ela faz

Esta skill orienta a adição de reprodução com o Google Cast a um app Android com a biblioteca Media3. Cobre dependências, manifesto, opções do Cast e o player para telas em Compose e em View. É para desenvolvedores Android que querem suporte ao Cast ou estão saindo do SDK legado do Cast.

Quando usar

  • ✓Quando você quer que os usuários transmitam vídeo ou áudio do seu app Android para uma TV ou um alto-falante.
  • ✓Quando você precisa migrar um app do SDK legado do Google Cast para o Media3 Cast.
  • ✓Quando você quer configurar o player do Cast e o provedor de opções em um app em Compose ou em View.

Link da skill

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

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/android/skills/blob/main/media/media3-cast-integration/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Adicione o Google Cast ao meu app Android de vídeo usando o Media3 para que os usuários transmitam para a TV.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

A skill verifica se a versão do Media3 é a 1.9.0 ou mais nova e depois adiciona as dependências e as entradas de manifesto necessárias. Em seguida configura as opções do Cast e o player do Cast para as telas do app.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do 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

Perguntas frequentes

Qual versão do Media3 é necessária?

O Media3 deve estar na versão 1.9.0 ou mais nova, já que o Cast não está disponível em versões anteriores.

Devo usar o SDK legado do Cast?

Não. A skill diz que o SDK legado está em modo de manutenção, então novas configurações devem usar o Media3 Cast, a menos que você peça o SDK legado.

Funciona com Compose e com Views?

Sim. Cobre a reprodução com Cast tanto em telas Compose quanto em telas baseadas em View.

Detalhes

Descrição original do 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

Popularidade

Estrelas no GitHub
10 mil
Posição no ranking
#11923
Licença
Apache-2.0
Atualizada em
29/10/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas