Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Cấu trúc ưu tiên của một ứng dụng âm thanh là thiết kế máy khách/máy chủ. Ứng dụng khách là một Hoạt động trong ứng dụng của bạn bao gồm MediaBrowser, trình điều khiển nội dung nghe nhìn và giao diện người dùng. Máy chủ là một MediaBrowserService chứa trình phát và một phiên phát nội dung đa phương tiện.
MediaBrowserService cung cấp hai tính năng chính:
Khi bạn sử dụng MediaBrowserService, các thành phần và ứng dụng khác có MediaBrowser có thể khám phá dịch vụ của bạn, tạo trình điều khiển nội dung nghe nhìn riêng, kết nối với phiên phát nội dung nghe nhìn của bạn và điều khiển trình phát. Đây là cách ứng dụng Wear OS và ứng dụng Android Auto có quyền truy cập vào ứng dụng đa phương tiện của bạn.
Dịch vụ này cũng cung cấp một API duyệt web không bắt buộc. Các ứng dụng không phải sử dụng tính năng này. API duyệt qua cho phép khách hàng truy vấn dịch vụ và xây dựng bản trình bày phân cấp nội dung của dịch vụ, có thể đại diện cho danh sách phát, thư viện nội dung nghe nhìn hoặc một số loại bộ sưu tập khác.
Cách tạo dịch vụ trình duyệt nội dung đa phương tiện có chứa một phiên phát nội dung đa phương tiện, quản lý kết nối ứng dụng và trở thành dịch vụ trên nền trước trong khi phát âm thanh.
Cách tạo hoạt động trên ứng dụng trình duyệt nội dung đa phương tiện có chứa giao diện người dùng và trình điều khiển nội dung đa phương tiện, cũng như kết nối và giao tiếp với một dịch vụ trình duyệt nội dung đa phương tiện.
Mô tả cách các phương thức gọi lại phiên phát nội dung đa phương tiện quản lý phiên phát nội dung đa phương tiện, dịch vụ trình duyệt nội dung đa phương tiện và các thành phần khác của ứng dụng như thông báo và broadcast receiver.
Mẫu GitHub này cho biết cách triển khai một ứng dụng đa phương tiện cho phép phát âm thanh ở chế độ nền và cung cấp thư viện nội dung nghe nhìn để hiển thị với các ứng dụng khác.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[],null,["# Audio app overview\n\nThe preferred architecture for an audio app is a client/server design. The client is an Activity in your app that includes a `MediaBrowser`, media controller, and the UI. The server is a `MediaBrowserService` containing the player and a media session.\n\nA `MediaBrowserService` provides two main features:\n\n- When you use a `MediaBrowserService`, other components and applications with a `MediaBrowser` can discover your service, create their own media controller, connect to your media session, and control the player. This is how Wear OS and Android Auto Applications gain access to your media application.\n- It also provides an optional *browsing API*. Applications don't have to use this feature. The browsing API lets clients query the service and build out a representation of its content hierarchy, which might represent playlists, a media library, or some other kind of collection.\n\n| **Note:** As is the case with media session and media controller, the recommended implementation of media browser services and media browsers are the classes `MediaBrowserServiceCompat` and `MediaBrowserCompat`, which are defined in the [media-compat support library](https://developer.android.com/topic/libraries/support-library/features.html#v4-media-compat). They replace earlier versions of the classes `MediaBrowserService` and `MediaBrowser` that were introduced in API 21. For brevity, the terms \"MediaBrowserService\" and \"MediaBrowser\" refer to instances of `MediaBrowserServiceCompat` and `MediaBrowserCompat` respectively.\n\n**[Building a media browser service](/guide/topics/media-apps/audio-app/building-a-mediabrowserservice)**\n: How to create a media browser service that contains a media session, manage client connections, and become a foreground service while playing audio.\n\n**[Building a media browser client](/guide/topics/media-apps/audio-app/building-a-mediabrowser-client)**\n: How to create a media browser client activity that contains a UI and media controller, and connect and communicate with a media browser service.\n\n**[Media session callbacks](/guide/topics/media-apps/audio-app/mediasession-callbacks)**\n: Describes how the media session callback methods manage the media session, media browser service, and other app components like notifications and broadcast receivers.\n\n**[Universal Android Music Player Sample](https://github.com/android/uamp)**\n: This GitHub sample shows how to implement a media app that allows background playback of audio, and provides a media library that is exposed to other apps."]]