Cast 프레임워크는 수신기에서 순차적으로 재생할 수 있는 MediaQueueItem 인스턴스 목록 생성을 지원하는 대기열 클래스를 제공합니다. 이 인스턴스는 동영상 또는 오디오 스트림과 같은 MediaInfo 인스턴스에서 빌드할 수 있습니다. 이 콘텐츠 항목 대기열은 수정, 재정렬, 업데이트 등을 할 수 있습니다.
리시버 SDK는 대기열에 현재 활성 상태 (재생 중 또는 일시중지됨)인 항목이 하나 이상 있는 한 대기열을 유지하고 대기열의 작업에 응답합니다. 전송자는 세션에 참여하여 대기열에 항목을 추가할 수 있습니다. 수신자는 마지막 항목의 재생이 완료되거나, 발신자가 재생을 중지하고 세션을 종료하거나, 발신자가 수신자에 새 대기열을 로드할 때까지 대기열 항목의 세션을 유지합니다. 수신기는 기본적으로 종료된 대기열에 관한 정보를 유지하지 않습니다. 대기열의 마지막 항목이 끝나면 미디어 세션이 종료되고 대기열이 사라집니다.
미디어 대기열 항목 만들기 및 로드
미디어 대기열 항목은 Cast 프레임워크에서 MediaQueueItem 인스턴스로 표현됩니다.
적응형 콘텐츠와 함께 미디어 플레이어 라이브러리를 사용하는 경우 미디어 대기열 항목을 만들 때 대기열에서 해당 항목 앞에 있는 항목의 재생이 끝나기 전에 플레이어가 미디어 대기열 항목의 버퍼링을 시작할 수 있도록 미리 로드 시간을 설정할 수 있습니다. 항목의 자동 재생 속성을 true로 설정하면 수신기가 자동으로 재생할 수 있습니다. 예를 들어 빌더 패턴을 사용하여 다음과 같이 미디어 대기열 항목을 만들 수 있습니다.
RemoteMediaClient의 적절한 queueLoad 메서드를 사용하여 대기열에 미디어 대기열 항목 배열을 로드합니다.
미디어 대기열 상태 업데이트 수신
수신기가 미디어 대기열 항목을 로드하면 세션 기간 (및 대기열 수명) 동안 유지되는 고유 ID가 항목에 할당됩니다. 앱은 현재 로드된 항목(재생 중이 아닐 수 있음), 로드 중인 항목, 미리 로드된 항목 측면에서 대기열의 상태를 알 수 있습니다. MediaStatus 클래스는 다음 상태 정보를 제공합니다.
getLoadingItemId() 메서드 - 수신기에서 현재 로드 중이지만 대기열에서 활성화되지 않은 항목의 항목 ID를 반환합니다.
getCurrentItemId()
메서드 - 미디어 상태 변경이 발생한 시점에 대기열에서 활성 상태였던 항목의 항목 ID를 반환합니다 (재생 중이 아닐 수도 있음).
getQueueItems()(지원 중단됨, 대신 MediaQueue 사용) 메서드 - MediaQueueItem 인스턴스 목록을 수정 불가능한 목록으로 반환합니다.
앱은 MediaQueue 클래스를 사용하여 항목 목록을 가져올 수도 있습니다. 이 클래스는 미디어 대기열의 스파스 데이터 모델입니다. 수신기와 자동으로 동기화되는 대기열에 항목 ID 목록을 유지합니다.
MediaQueue는 대기열이 매우 길 때 메모리를 너무 많이 사용하므로 모든 MediaQueueItem를 유지하지 않습니다. 대신 요청 시 항목을 가져오고 최근에 액세스한 항목의 LruCache를 유지합니다. 다음 메서드를 사용하여 미디어 대기열에 액세스할 수 있습니다.
예를 들어 MediaQueueRecyclerViewAdapter을 사용하여 RecyclerView를 만들려면 다음을 실행합니다.
Kotlin
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);}
대기열 수정
대기열의 항목을 조작하려면 RemoteMediaClient 클래스의 대기열 메서드를 사용합니다. 이를 통해 항목 배열을 새 대기열에 로드하고, 기존 대기열에 항목을 삽입하고, 대기열에 있는 항목의 속성을 업데이트하고, 대기열에서 항목을 앞뒤로 이동하고, 대기열 자체의 속성을 설정하고(예: 다음 항목을 선택하는 repeatMode 알고리즘 변경), 대기열에서 항목을 삭제하고, 대기열의 항목 순서를 변경할 수 있습니다.
[[["이해하기 쉬움","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-09-05(UTC)"],[[["\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."]]