在裝置之間轉送
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用者會透過無線技術連結電視、家庭劇院系統和音樂播放器,並希望能在這些更大聲的裝置上播放 Android 應用程式的內容。啟用這類播放功能後,原本只能供單一使用者在單一裝置上使用的應用程式,就能成為多人共享的體驗,讓使用者感到愉悅和啟發。
Android 媒體路由器 API 的設計宗旨,是透過通用使用者介面,在遠端接收裝置上啟用媒體顯示和播放功能。應用程式開發人員實作 MediaRouter
介面後,即可連線至架構,並在參與媒體路由器架構的裝置上播放內容。媒體播放裝置製造商可以發布 MediaRouteProvider
,讓其他應用程式連線至接收器裝置並在上面播放媒體,藉此參與架構。圖 1 說明應用程式如何透過媒體路由器架構連線至接收器裝置。
圖 1. 總覽媒體路徑供應商類別如何從媒體應用程式提供通訊給接收器裝置。
注意:如要讓應用程式支援 Google Cast 裝置,請使用 Cast SDK,並將應用程式建構為 Cast 傳送器。請按照 Cast 說明文件中的指示操作,不要直接使用 MediaRouter 架構。
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 開始,系統媒體播放器也會顯示應用程式的轉送選項。這樣一來,使用者在不同裝置間切換時,就能享有流暢體驗,例如在廚房觀看影片,或是在手機上觀看影片;在家中或車上聆聽音訊。
在媒體通知中按下路徑選取按鈕,預設會顯示輸出切換器,並提供下列選項:
應用程式也可能視功能提供更多選項,例如 Cast。
應用程式可以使用 MediaRouter
API 自訂路線選項。您可以排除不支援的裝置 (例如在 Netflix 智慧電視上觀看影片時,篩除僅支援音訊的 Chromecast),或納入應用程式可辨識的其他特殊裝置。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-27 (世界標準時間)。"],[],[],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."]]