classMyRecyclerViewAdapter(mediaQueue:MediaQueue?):MediaQueueRecyclerViewAdapter<MyViewHolder?>(mediaQueue){overridefunonBindViewHolder(holder:MyViewHolder,position:Int){valitem=getItem(position)// Update the view using `item`....}}classMyViewHolder:RecyclerView.ViewHolder{// Implement your own ViewHolder....}funsomeMethod(){valadapter=MyRecyclerViewAdapter(mCastSession.remoteMediaClient.getMediaQueue())valrecyclerView=activity.findViewById(R.id.my_recycler_view_id)asRecyclerViewrecyclerView.adapter=adapter}
Java
publicclassMyRecyclerViewAdapterextendsMediaQueueRecyclerViewAdapter<MyViewHolder>{publicMyRecyclerViewAdapter(MediaQueuemediaQueue){super(mediaQueue);}@OverridepublicvoidonBindViewHolder(MyViewHolderholder,intposition){MediaQueueItemitem=getItem(position);// Update the view using `item`....}}publicclassMyViewHolderimplementsRecyclerView.ViewHolder{// Implement your own ViewHolder....}publicvoidsomeMethod(){RecyclerView.Adapteradapter=newMyRecyclerViewAdapter(mCastSession.getRemoteMediaClient().getMediaQueue());RecyclerViewrecyclerView=(RecyclerView)getActivity().findViewById(R.id.my_recycler_view_id);recyclerView.setAdapter(adapter);}
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eDesign a settings experience for your car screen app, focusing on essential settings and error handling flows.\u003c/p\u003e\n"],["\u003cp\u003eUtilize Android for Cars App Library templates, such as the List and Message templates, to build a user-friendly settings interface.\u003c/p\u003e\n"],["\u003cp\u003ePrioritize simplicity and ease of navigation, including only necessary settings and organizing them on a single screen if possible.\u003c/p\u003e\n"],["\u003cp\u003eAdhere to the UX requirements for the Android for Cars App Library to ensure a seamless user experience.\u003c/p\u003e\n"],["\u003cp\u003eRemember to declare a Settings activity in your app's manifest file for proper implementation.\u003c/p\u003e\n"]]],[],null,["# Queueing\n\nThe Cast framework provides queueing classes that support the creation of lists\nof [`MediaQueueItem`](/cast/docs/reference/android/com/google/android/gms/cast/MediaQueueItem)\ninstances, which can be built from `MediaInfo` instances such as video or audio\nstreams, to play sequentially on the receiver. This queue of content items\ncan be edited, reordered, updated, and so forth.\n| **Note:** Review the [Google Cast Autoplay](/cast/docs/design_checklist/cast-autoplay) for best practices when designing an autoplay/queueing experience for Cast.\n\nThe Receiver SDK maintains the queue and responds to operations on the\nqueue as long as the queue has at least one item currently active (playing or\npaused). Senders can join the session and add items to the queue. The receiver\nmaintains a session for queue items until the last item completes playback or\nthe sender stops the playback and terminates the session, or until a sender\nloads a new queue on the receiver. The receiver does not maintain any\ninformation about terminated queues by default. Once the last item in the queue\nfinishes, the media session ends and the queue vanishes.\n| **Note:** The [`Styled Media Receiver`](/cast/docs/styled_receiver) and [`Default Media Receiver`](/cast/docs/receiver_apps#default) do not support a queue of images; only a queue of audio or video streams is supported in the styled and default receivers.\n\nCreate and load media queue items\n---------------------------------\n\nA media queue item is represented in the Cast framework as a\n[`MediaQueueItem`](/android/reference/com/google/android/gms/cast/MediaQueueItem)\ninstance.\nWhen you create a media queue item, if you are using the [Media Player\nLibrary](/cast/docs/reference/player) with adaptive content, you can set the\npreload time so that the player can begin buffering the media queue item before\nthe item ahead of it in the queue finishes playing. Setting the item's autoplay\nattribute to true allows the receiver to play it automatically. For example,\nyou can use a builder pattern to create your media queue item as follows:\nKotlin \n\n```kotlin\nval queueItem: MediaQueueItem = MediaQueueItem.Builder(mediaInfo)\n .setAutoplay(true)\n .setPreloadTime(20.0)\n .build()\n```\nJava \n\n```java\nMediaQueueItem queueItem = new MediaQueueItem.Builder(mediaInfo)\n .setAutoplay(true)\n .setPreloadTime(20)\n .build();\n```\n\nLoad an array of media queue items in the queue by using the appropriate\n[`queueLoad`](/cast/docs/reference/android/com/google/android/gms/cast/framework/media/RemoteMediaClient#queueLoad(com.google.android.gms.cast.MediaQueueItem%5B%5D,%20int,%20int,%20long,%20org.json.JSONObject))\nmethod of `RemoteMediaClient`.\n\nReceive media queue status updates\n----------------------------------\n\nWhen the receiver loads a media queue item, it assigns a unique ID to the item\nwhich persists for the duration of the session (and the life of the queue). Your\napp can learn the status of the queue in terms of which item is currently loaded\n(it might not be playing), loading, or preloaded. The\n[`MediaStatus`](/android/reference/com/google/android/gms/cast/MediaStatus#constant-summary)\nclass provides this status information:\n\n- [`getPreloadedItemId()`](/android/reference/com/google/android/gms/cast/MediaStatus#getPreloadedItemId()) method - If the next item has been preloaded, returns the preloaded item ID.\n- [`getLoadingItemId()`](/android/reference/com/google/android/gms/cast/MediaStatus#getLoadingItemId()) method - Returns the item ID of the item that is currently loading (but isn't active in the queue) on the receiver.\n- [`getCurrentItemId()`](/android/reference/com/google/android/gms/cast/MediaStatus#getCurrentItemId()) method - Returns the item ID of the item that that was active in the queue (it might not be playing) at the time the media status change happened.\n- [`getQueueItems()`](/android/reference/com/google/android/gms/cast/MediaStatus#getQueueItems()) (**Deprecated, use `MediaQueue` instead** ) method - Returns the list of `MediaQueueItem` instances as an unmodifiable list.\n\nYour app can also get the list of items using the\n[`MediaQueue`](/android/reference/com/google/android/gms/cast/framework/media/MediaQueue)\nclass. The class is a sparse data model of the media queue. It keeps the list of\nitem IDs in the queue, which is automatically synchronized with the receiver.\n`MediaQueue` doesn't keep all the\n[`MediaQueueItem`](/android/reference/com/google/android/gms/cast/MediaQueueItem)\nbecause it will take too much memory when the queue is very long. Instead, it\nfetches the items on demand and keeps an [`LruCache`](https://developer.android.com/reference/android/util/LruCache.html) of\nrecently accessed items. You can use these methods to access the media queue:\n\n- [`getItemIds()`](/android/reference/com/google/android/gms/cast/framework/media/MediaQueue#getItemIds()) method - Returns the list of all item IDs in order.\n- [`getItemAtIndex()`](/android/reference/com/google/android/gms/cast/framework/media/MediaQueue#getItemAtIndex(int)) method - Returns the cached item at a given index. If the item is not cached, `MediaQueue` will return `null` and schedule to fetch the item. When the item is fetched, [`MediaQueue.Callback#itemsUpdatedAtIndexes()`](/android/reference/com/google/android/gms/cast/framework/media/MediaQueue.Callback#itemsUpdatedAtIndexes(int%5B%5D)) will be called, and calling `getItemAtIndex()` with the same ID again will return the item.\n- [`fetchMoteItemsRelativeToIndex()`](/android/reference/com/google/android/gms/cast/framework/media/MediaQueue#getItemIds(int,%0Aint,%20int)) is used when the user scrolls the queue UI to the top or bottom, and your app wants to fetch more items from the cloud.\n\nUse these methods together with the other media status methods to inform your\napp about the status of the queue and the items in the queue. In addition to\nmedia status updates from the receiver, your app can listen for changes to the\nqueue by implementing\n[`RemoteMediaClient.Callback`](/cast/docs/reference/android/com/google/android/gms/cast/framework/media/RemoteMediaClient.Callback)\nand\n[`MediaQueue.Callback`](/android/reference/com/google/android/gms/cast/framework/media/MediaQueue.Callback).\n| **Note:** To provide the best user experience, the sender app must show the next autoplay item in the queue in the sender UI.\n\nAlso, the Cast SDK provides two utility classes to create UI for queueing.\n\n- [`MediaQueueRecyclerViewAdapter`](/cast/docs/reference/android/com/google/android/gms/cast/framework/media/MediaQueueRecyclerViewAdapter), for backing the data of [`RecyclerView`](https://developer.android.com/jetpack/androidx/releases/recyclerview)\n- [`MediaQueueListAdapter`](/cast/docs/reference/android/com/google/android/gms/cast/framework/media/MediaQueueListAdapter), for backing the data of [`ListAdapter`](https://developer.android.com/reference/android/widget/ListAdapter.html).\n\nFor example, to create a `RecyclerView` using `MediaQueueRecyclerViewAdapter`:\nKotlin \n\n```kotlin\nclass MyRecyclerViewAdapter(mediaQueue: MediaQueue?) :\n MediaQueueRecyclerViewAdapter\u003cMyViewHolder?\u003e(mediaQueue) {\n override fun onBindViewHolder(holder: MyViewHolder, position: Int) {\n val item = getItem(position)\n\n // Update the view using `item`.\n ...\n }\n}\n\nclass MyViewHolder : RecyclerView.ViewHolder {\n // Implement your own ViewHolder.\n ...\n}\n\nfun someMethod() {\n val adapter = MyRecyclerViewAdapter(\n mCastSession.remoteMediaClient.getMediaQueue())\n val recyclerView =\n activity.findViewById(R.id.my_recycler_view_id) as RecyclerView\n recyclerView.adapter = adapter\n}\n```\nJava \n\n```java\npublic class MyRecyclerViewAdapter extends MediaQueueRecyclerViewAdapter\u003cMyViewHolder\u003e {\n public MyRecyclerViewAdapter(MediaQueue mediaQueue) {\n super(mediaQueue);\n }\n\n @Override\n public void onBindViewHolder(MyViewHolder holder, int position) {\n MediaQueueItem item = getItem(position);\n\n // Update the view using `item`.\n ...\n }\n}\n\npublic class MyViewHolder implements RecyclerView.ViewHolder {\n // Implement your own ViewHolder.\n ...\n}\n\npublic void someMethod() {\n RecyclerView.Adapter adapter = new MyRecyclerViewAdapter(\n mCastSession.getRemoteMediaClient().getMediaQueue());\n RecyclerView recyclerView =\n (RecyclerView) getActivity().findViewById(R.id.my_recycler_view_id);\n recyclerView.setAdapter(adapter);\n}\n```\n\nEdit the queue\n--------------\n\nTo operate on the items in the queue, use the queue methods of the\n[`RemoteMediaClient`](/cast/docs/reference/android/com/google/android/gms/cast/framework/media/RemoteMediaClient#pubmethods)\nclass. These let you load an array of items into a new queue, insert items into\nan existing queue, update the properties of items in the queue, make an item\njump forward or backward in the queue, set the properties of the queue itself\n(for example, change the `repeatMode` algorithm that selects the next item),\nremove items from the queue, and reorder the items in the queue."]]