Vòng đời của dịch vụ trình duyệt nội dung đa phương tiện
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.
Phần này mô tả cách Android Automotive OS (AAOS) và Android Auto tương tác với dịch vụ trình duyệt nội dung đa phương tiện của bạn trong quy trình làm việc thông thường của người dùng:
Người dùng chạy ứng dụng của bạn trên AAOS hoặc Android Auto.
Ứng dụng lưu trữ liên kết với dịch vụ trình duyệt nội dung đa phương tiện của bạn. Hệ điều hành sẽ khởi động dịch vụ này nếu dịch vụ chưa chạy. Trong quá trình triển khai phương thức onCreate()
, bạn phải tạo và đăng ký một đối tượng MediaSessionCompat
cũng như đối tượng gọi lại của đối tượng đó. Để tìm hiểu thêm, hãy xem bài viết Đăng ký một phiên nội dung nghe nhìn.
AAOS hoặc Android Auto gọi phương thức onGetRoot
của dịch vụ để truy xuất gốc trong hệ thống phân cấp nội dung. Thư mục gốc không xuất hiện.
Thay vào đó, mục này sẽ truy xuất thêm nội dung từ ứng dụng của bạn trong các bước tiếp theo.
AAOS hoặc Android Auto gọi phương thức onLoadChildren()
của dịch vụ để truy xuất các phần tử con của mục nội dung nghe nhìn gốc. AAOS và Android Auto hiển thị các mục nội dung đa phương tiện này ở cấp cao nhất của mục nội dung. Hãy xem phần Cấu trúc trình đơn gốc để tìm hiểu thêm về những gì hệ thống dự kiến.
Khi người dùng chọn một mục nội dung đa phương tiện có thể duyệt xem, phương thức onLoadChildren()
của dịch vụ sẽ được gọi lại.
Nếu người dùng chọn một mục nội dung nghe nhìn có thể phát, thì AAOS hoặc Android Auto sẽ gọi phương thức gọi lại phiên phát nội dung nghe nhìn thích hợp để thực hiện thao tác đó.
Nếu được ứng dụng của bạn hỗ trợ, người dùng cũng có thể tìm kiếm nội dung của bạn. Trong trường hợp này, AAOS hoặc Android Auto sẽ gọi phương thức onSearch()
của dịch vụ.
Để tìm hiểu thêm, hãy xem phần Hiển thị kết quả tìm kiếm có thể xem.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-22 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-22 UTC."],[],[],null,["# Media browser service lifecycle\n\nThis section describes how Android Automotive OS (AAOS) and Android Auto\ninteract with your media browser service during a typical user workflow:\n\n1. The user launches your app on AAOS or Android Auto.\n\n2. The host app binds to your media browser service, which the OS starts if it\n isn't already running. In your implementation of the `onCreate()` method,\n you must create and register a [`MediaSessionCompat`](/reference/android/support/v4/media/session/MediaSessionCompat) object and its\n callback object. To learn more, see [Register a media session](/training/cars/media/enable-playback#registering_mediasession).\n\n3. AAOS or Android Auto calls your service's [`onGetRoot`](/training/cars/media/content-hierarchy#onGetRoot) method to\n retrieve the root in your content hierarchy. The root is not displayed.\n Instead, it retrieves more content from your app in subsequent steps.\n\n4. AAOS or Android Auto calls your service's [`onLoadChildren()`](/reference/androidx/media/MediaBrowserServiceCompat#onLoadChildren(java.lang.String,androidx.media.MediaBrowserServiceCompat.Result%3Cjava.util.List%3Candroid.support.v4.media.MediaBrowserCompat.MediaItem%3E%3E)%5D) method to\n retrieve the descendants of the root media item. AAOS and Android Auto\n display these media items as the top level of content items. See\n [Structure the root menu](/training/cars/media/content-media-browser/content-hierarchy#root-menu-structure) to learn more about what the system expects.\n\n5. When the user selects a **browsable** media item, your service's\n `onLoadChildren()` method is called again.\n\n6. If the user selects a **playable** media item, AAOS or Android Auto calls\n the appropriate media session callback method to perform the action.\n\n7. If supported by your app, the user can also search your content. In this\n case, AAOS or Android Auto call your service's [`onSearch()`](/reference/androidx/media/MediaBrowserServiceCompat#onSearch(java.lang.String,android.os.Bundle,androidx.media.MediaBrowserServiceCompat.Result%3Cjava.util.List%3Candroid.support.v4.media.MediaBrowserCompat.MediaItem%3E%3E)) method.\n To learn more, see [Display browsable search results](/training/cars/media/create-media-browser/browsable-search)."]]