デバイス間のルーティング
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ユーザーはテレビ、ホームシアター システム、音楽プレーヤーをワイヤレス技術で接続するようになり、こうした画面や音量の大きいデバイスで Android アプリのコンテンツを再生できるようになることを望んでいます。このような再生を可能にすることで、単一デバイス上の単一ユーザー向けのアプリを、複数のユーザー間で共有して楽しんでもらうことができます。
Android Media Router API は、一般的なユーザー インターフェースを使ってリモートの受信デバイスでメディアの表示と再生を行えるように設計されています。アプリ デベロッパーは、MediaRouter
インターフェースを実装することでメディア ルーター フレームワークに接続でき、それによって、このフレームワークに参加しているデバイス上でコンテンツを再生できます。メディア再生デバイスのメーカーは、他のアプリから受信デバイスに接続してメディアを再生できるように MediaRouteProvider
を公開することによって、このフレームワークに参加できます。図 1 に、アプリからメディア ルーター フレームワークを介して受信デバイスに接続する仕組みを示します。
図 1. メディア ルート プロバイダ クラスがメディアアプリから受信デバイスに通信する仕組みの概要
注: アプリで Google Cast デバイスをサポートする場合は、Cast SDK を使用し、アプリをキャストの送信元としてビルドします。MediaRouter フレームワークを直接使用するのではなく、Cast ドキュメントに記載の説明を参考にしてください。
MediaRouter サポート ライブラリ
MediaRouter API は AndroidX MediaRouter ライブラリで定義されています。このライブラリは、Android 2.3(API レベル 9)以上を搭載するデバイスと互換性があり、そのすべてにわたって一貫したエクスペリエンスを提供します。MediaRouter API について詳しくは、API リファレンスの androidx.mediarouter.media
パッケージをご覧ください。
- MediaRouter API
- メディアアプリは
MediaRouter
API を使用して、利用可能なリモートの再生デバイスを発見し、音声と動画をそのデバイスに転送できます。 - MediaRouteProvider API
MediaRouteProvider
API は、リモートの再生デバイスの機能を定義し、MediaRouter
を使って代替メディアパスを検索するアプリに、その定義を公開します。
出力の切り替え

Android 11 以降、アプリのルーティング オプションもシステム メディア プレーヤーに表示されます。それによりユーザーは、スマートフォンで視聴していた動画をキッチンで見続けたり、自宅でも車内でもオーディオを聞いたりなど、視聴形態を変えながらデバイスをシームレスに切り替えることが可能になります。
メディア通知のルート選択ボタンを押すと、出力の切り替えが表示されます。デフォルトで次の選択ができます。
- 現在のデバイスのスピーカー
- 接続されているすべての Bluetooth オーディオ デバイス
アプリには、たとえばキャストなど、機能に応じてさまざまなオプションが用意されています。
アプリでは MediaRouter
API を使用してルーティングの選択肢をカスタマイズできます。使用しないデバイスの除外(Netflix スマートテレビの視聴中に音声のみの Chromecast を除外するなど)や、アプリが認識するその他の特別なデバイスの追加などが可能です。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-27 UTC。
[null,null,["最終更新日 2025-08-27 UTC。"],[],[],null,["# Routing between devices\n\nAs users connect their televisions, home theater systems, and music players with wireless\ntechnologies, they want to be able to play content from Android apps on these larger,\nlouder devices. Enabling this kind of playback can turn your one-device, one-user app\ninto a shared experience that delights and inspires multiple users.\n\n\u003cbr /\u003e\n\nThe Android media router APIs are designed to enable media display and playback on\nremote receiver devices using a common user interface. App developers that\nimplement a [MediaRouter](/reference/androidx/mediarouter/media/MediaRouter) interface can then connect to the\nframework and play content to devices that participate in the media router framework. Media\nplayback device manufacturers can participate in the framework by publishing a [MediaRouteProvider](/reference/androidx/mediarouter/media/MediaRouteProvider) that allows other applications to connect to and\nplay media on the receiver devices. Figure 1 illustrates how an app connects to a receiver\ndevice through the media router framework.\n\n\u003cbr /\u003e\n\n\n**Figure 1.** Overview of how media route provider classes provide communication\nfrom a media app to a receiver device.\n\n\u003cbr /\u003e\n\n\n**Note:** If you want your app to support\n[Google Cast](https://developers.google.com/cast/) devices,\nyou should use the [Cast SDK](https://developers.google.com/cast/docs/reference/)\nand build your app as a Cast sender. Follow the directions in the\n[Cast documentation](https://developers.google.com/cast/docs/android_sender_setup)\ninstead of using the MediaRouter framework directly.\n\nMediaRouter support library\n---------------------------\n\nThe mediarouter APIs are defined in the\n[AndroidX MediaRouter library](/guide/topics/media/mediarouter).\nThis library is compatible with devices running Android 2.3 (API level 9) and higher and ensures a consistent\nexperience across all of them.\nFor detailed information about the mediarouter APIs, see the [androidx.mediarouter.media](/reference/androidx/mediarouter/media/package-summary)\npackage in the API reference.\n\n**[MediaRouter API](/guide/topics/media/mediarouter)**\n: A media app uses the `MediaRouter` API to discover available remote playback devices and to route audio and video to them.\n\n**[MediaRouteProvider API](/guide/topics/media/mediarouteprovider)**\n: The `MediaRouteProvider` API defines the capabilities of a remote playback device and makes it visible to apps that use a `MediaRouter` to search for alternative media paths.\n\nThe output switcher\n-------------------\n\nStarting with Android 11, your app's routing\noptions also appear in the system media player. This helps to give the user a\nseamless journey when moving between devices as they change their viewing and\nlistening contexts, such as watching video in the kitchen versus on a phone,\nor listening to audio in the home or car.\n\nPressing the route selection button in a media notification brings up the\noutput switcher with these choices by default:\n\n- The speaker on the current device\n- All connected Bluetooth audio devices\n\nApps can also provide more options depending on their capabilities, such as Cast.\n\nApps can use the [`MediaRouter`](/reference/androidx/mediarouter/media/MediaRouter)\nAPI to customize\nthe routing choices. You can exclude devices you don't support (like filtering\nout audio-only Chromecast if you're watching a Netflix smart TV) or include\nother special devices that your app recognizes."]]