media3-cast-integration
できること
このスキルは、Media3を使ってAndroidアプリにGoogle Castの再生を追加する方法を導きます。依存関係、マニフェスト、Castのオプション、ComposeとViewの画面のためのプレーヤーを扱います。Castのサポートを加えたい、または古いCast SDKから移行するAndroid開発者向けです。
使う場面
- ✓利用者が、Androidアプリの動画や音声を、テレビやスピーカーにキャストできるようにしたいとき。
- ✓古いGoogle Cast SDKから、Media3 Castに移行する必要があるとき。
- ✓ComposeまたはViewのアプリで、Castのプレーヤーとオプションのプロバイダーを設定したいとき。
スキルのリンク
https://github.com/android/skills/blob/main/media/media3-cast-integration/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Media3を使って、Androidの動画アプリにGoogle Castを追加し、利用者がテレビにキャストできるようにしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、Media3のバージョンが1.9.0以上であることを確認し、必要な依存関係とマニフェストの項目を追加します。そのうえで、Castのオプションと、アプリの画面用のCastプレーヤーを設定します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Prerequisites
- Jetpack Media3 version must be
>= 1.9.0. Cast isn't available in lower versions.
Glossary
CastPlayer: Media3Playerthat controls playback on both local and remote Cast devices.RemoteCastPlayer: Media3Playerthat 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 GMSCastContext.
Common guidelines
- Legacy Google Cast SDK is in maintenance mode.
- For new Cast setups:
- You must use Jetpack Media3 Cast.
- You mustn't use legacy Cast SDK unless explicitly requested.
Step 1: Set up dependencies
To complete this step, you MUST ensure the following:
In the app-level build file, declare the
media3-castdependency version 1.9.0 or higher.implementation("androidx.media3:media3-cast:1.11.1")Ensure required Media3 dependencies are present:
androidx.media3:media3-exoplayerandroidx.media3:media3-sessionandroidx.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.
- Verify legacy Cast SDK (
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
DefaultCastOptionsProviderby default. See the "OptionsProvider" section in Getting started with CastPlayer. - Declare a custom
OptionsProvideronly if explicitly requested. See Customize CastOptions. - Ensure
INTERNETpermission 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
ExoPlayeronly to support local playback. - Legacy Cast setup: Uses
ExoPlayerfor local playback, alongside aPlayerwrapper over the legacyRemoteMediaClientfor remote playback. The UI interfaces with aMediaSessioninteracting with aForwardingPlayer, which finally routes controls to either local or remote playback.
To complete this step, you MUST ensure the following:
- Inside the application's
MediaSessionService(orMediaLibraryService)onCreate()method, initializeExoPlayerandCastPlayer. - Use
CastPlayerby default unlessRemoteCastPlayeris explicitly requested. See the "Build a CastPlayer" section in Getting started with CastPlayer. - For
CastPlayer, pass the instance directly toMediaSession.Builder. - Replace all legacy forwarding player wrappers.
- Don't delete legacy class files yet to prevent compilation errors during migration.
Advanced: RemoteCastPlayer
Use
RemoteCastPlayeronly if explicitly requested by user.Initialize
MediaSessionwithlocalPlayerand set aSessionAvailabilityListeneronRemoteCastPlayerto 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
よくある質問
必要なMedia3のバージョンは何ですか?
Castは以前のバージョンでは使えないため、Media3は1.9.0以上である必要があります。
古いCast SDKを使うべきですか?
いいえ。古いSDKは保守モードにあるため、新しい設定では、あなたが古いSDKを求めない限りMedia3 Castを使うべきだとこのスキルは述べています。
ComposeとViewの両方で動きますか?
はい。ComposeとViewベースの両方の画面でのCastの再生を扱います。
詳細
作者による元の説明
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
人気
- GitHubのスター
- 10k
- ランキング
- #11923
- ライセンス
- Apache-2.0
- 更新日
- 2026/10/29
コメント
- …
このリポジトリの他のスキル
agp-9-upgrade
10kエージェントが、AndroidアプリをAndroid Gradle Plugin 9にアップグレードし、その破壊的変更に対応できるよう支援します。マルチプラットフォームのプロジェクトは対象外です。
camerax
10kエージェントが、CameraXを使ってAndroidのカメラ機能を作れるよう支援します。動画の録画、ハードウェアの制御、ML Kit、Media3のエフェクトを含みます。
android-for-cars-parked-apps
10kエージェントが、Androidの動画、ゲーム、ブラウザのアプリを、Android AutoとAndroid Automotiveで駐車中のアプリとして動かせるように適合させるよう支援します。
appfunctions
10kエージェントが、Androidアプリの主要な作業の流れを見つけ、AIエージェントや音声コマンドが実行できるAppFunctionsとして公開できるよう支援します。
似ているスキル
android-clean-architecture
280kエージェントがAndroidプロジェクトを効率よく整理できるようにします。コードを構造化して、保守や新機能の開発をしやすくします。
compose-multiplatform-patterns
280kエージェントがKMPプロジェクトでCompose MultiplatformとJetpack Composeのパターンを使えるようにします。状態管理、ナビゲーション、テーマ設定、パフォーマンスを扱います。
dart-flutter-patterns
280kエージェントがDartとFlutterのアプリ向けのコードを書けるようにします。最新のパターンを使い、堅牢で管理しやすいアプリを作ります。