[[["容易理解","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-07-27 (世界標準時間)。"],[],[],null,["# Media controls in System UI\n\nStarting in Android 13, media controls in System UI\ncontain updates to action buttons and remote playback. These changes support a\nmore polished media control experience on phones and tablets, and offer seamless\nmedia transfers across devices.\n\nUpdates to media controls\n-------------------------\n\nThis section describes the updates made to media controls in Android 13\nfor action buttons and remote playback.\n\n### Action button changes\n\nTo ensure that users can access a rich set of media controls for apps playing\nmedia, action buttons on media controls for Android 13\nare derived from the [`PlaybackState`](https://developer.android.com/reference/android/media/session/PlaybackState)\naction states.\nWith this change, the function [`MediaDataManager#createActionsFromState`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt#811)\ngenerates action button information based on the `PlaybackState` action state.\nThis aligns with how media controls are rendered in other Android platforms such\nas Auto, Assistant, and Wear.\n\nIn contrast, in Android 12, the action buttons on media\ncontrols were determined by [notification actions](https://developer.android.com/reference/android/app/Notification.Action)\nadded to a [`MediaStyle`](https://developer.android.com/reference/android/app/Notification.MediaStyle)\nnotification.\n| **Note:** For backward compatibility, System UI continues to provide an alternate layout that uses notification actions for apps that don't update to target Android 13, or that don't include `PlaybackState` information.\n\nFor a summary of the app-compatible changes for the action button updates, see\n[`StatusBarManager`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/core/java/android/app/StatusBarManager.java#527).\n\n### Remote playback API\n\nTo deliver a cohesive media experience across a variety of surfaces, starting\nwith Android 13, a new system API [`Notification#setRemotePlaybackInfo`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/core/java/android/app/Notification.java#9096)\nis added to mark media notifications on the media control System UI for remote\nplayback. This API lets system apps that post the notifications do the\nfollowing:\n\n- Provide information and functionality for media originating on a remote device to the default output switcher on the media control.\n- Replace the output switcher affordance if necessary.\n\nSystem apps that use this notification must have the `MEDIA_CONTENT_CONTROL`\npermission.\n\nThe [`Notification#setRemotePlaybackInfo`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/core/java/android/app/Notification.java#9096) API also adds the\nfollowing [`extras`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt#678)\nto determine the name, icon, and intent of the remote playback device:\n\n- `Notification#EXTRA_MEDIA_REMOTE_DEVICE`\n- `Notification#EXTRA_MEDIA_REMOTE_ICON`\n- `Notification#EXTRA_MEDIA_REMOTE_INTENT`\n\nWith this information, System UI can replace the default output switcher chip\ndevice information and add the media control for remote playback to the end of\nthe list of local media controls.\n\nImplementation of media control\n-------------------------------\n\nOEMs must be aware of this change to default behavior, because it affects how\nmedia controls for apps are generated. OEMs must also ensure that the new system\nAPI works as applicable in their output switcher affordance.\n\nOEMs aren't required to make any changes and can use the\n[default implementation](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/packages/SystemUI/src/com/android/systemui/media/) in AOSP.\n\nCustomization of remote playback\n--------------------------------\n\nIn cases where the OEM has a system app that posts remote media playback\nnotifications, the app can optionally call `setRemotePlaybackInfo` for\nnotification as long as it has been granted the `MEDIA_CONTENT_CONTROL`\npermission. However, this isn't a requirement and the partner can choose not to\ncustomize.\n\nValidation of media control\n---------------------------\n\nTo test media control in System UI, run a manual test to validate the following:\n\n- The buttons function as intended while playing media from an app.\n- The output switcher displays the correct device information.\n\nUse the following tests to validate the remote playback API:\n\n- CTS tests in [`NotificationManagerTest`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/app/src/android/app/cts/NotificationManagerTest.java), such as [`testMediaStyleRemotePlayback_noPermission`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/app/src/android/app/cts/NotificationManagerTest.java#3605) and [`testMediaStyleRemotePlayback_hasPermission`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/app/src/android/app/cts/NotificationManagerTest.java#3629).\n- Unit tests under [`com.android.systemui.media`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/packages/SystemUI/tests/src/com/android/systemui/media/).\n\nRefer to the new [CDD requirement](/docs/compatibility/13/android-13-cdd#223_software) \\[3.8.3.1/H-1-SR\\]\nfor recommendations.\n| **Note:** A new [`MEDIA_SESSION_ACTIONS`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/packages/SystemUI/src/com/android/systemui/flags/Flags.java#154) flag is used only for testing. It enables `PlaybackState` actions for all apps and is set to off by default. Turning the flag on for apps that aren't updated to target Android 13 can cause the media controls to break if the appropriate `PlaybackState` isn't set."]]