Tìm nạp một cửa sổ các mục bằng cách sử dụng itemID được chỉ định làm tham chiếu. Phương thức này được MediaManager gọi khi cần thêm các mục trong hàng đợi, thường xuất phát từ yêu cầu của người gửi. Nếu bạn đặt nextCount hoặc prevCount, thì fetchItems sẽ chỉ trả về các mục sau hoặc trước mục tham chiếu. Nếu bạn đặt cả nextCount và prevCount, thì một cửa sổ các mục trong đó có itemId sẽ được trả về.
Khởi động hàng đợi bằng requestData. Được gọi khi trình nhận nhận được một yêu cầu cast.framework.messages.Command.LOAD mới. Nếu thuộc tính này trả về hoặc phân giải thành null, thì phương thức triển khai hàng đợi mặc định sẽ tạo một hàng đợi dựa trên queueData.items hoặc trên một mục nội dung đa phương tiện trong dữ liệu yêu cầu LOAD.
Đặt mục hiện tại thành itemId. Được MediaManager gọi khi thay đổi mục đang phát.
Thông số
itemId
number
Mã nhận dạng duy nhất của mục.
onItemsInserted
onItemsInserted(items, insertBefore)
Lệnh gọi lại cho biết các mục sau đã được chèn vào hàng đợi của trình nhận trong phiên này. Một phương thức triển khai trên đám mây có thể cập nhật hàng đợi dựa trên thông tin mới này.
Mã nhận dạng của mục nằm ngay sau danh sách được chèn. Nếu bạn không cung cấp mã nhận dạng thì danh sách đã chèn đã được thêm vào cuối danh sách chờ.
onItemsRemoved
onItemsRemoved(itemIds)
Lệnh gọi lại cho biết các mục sau đã bị xoá khỏi hàng đợi của trình nhận trong phiên này. Một phương thức triển khai trên đám mây có thể cập nhật hàng đợi dựa trên thông tin mới này.
Thông số
itemIds
Mảng số
Mã của các mục đã bị xoá.
Giá trị không được rỗng.
onItemsReordered
onItemsReordered(items, insertBefore)
Lệnh gọi lại cho biết các mặt hàng sau đã được sắp xếp lại.
Mã nhận dạng của mục nằm ngay sau danh sách được sắp xếp lại. Nếu bạn không cung cấp insertBefore, danh sách đã sắp xếp lại sẽ được thêm vào cuối hàng đợi.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003e\u003ccode\u003eQueueBase\u003c/code\u003e provides a foundational structure for managing media queues within the Cast framework.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods to initialize, fetch, and manipulate queue items, including shuffling and unshuffling.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can extend this base class to implement custom queueing logic for their Cast receiver applications.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eQueueBase\u003c/code\u003e interacts with \u003ccode\u003eMediaManager\u003c/code\u003e to handle queue updates and playback transitions.\u003c/p\u003e\n"],["\u003cp\u003eCallbacks are provided to inform developers about queue modifications like insertions, removals, and reordering.\u003c/p\u003e\n"]]],["The `QueueBase` class manages a media queue, fetching, initializing, and modifying items. Key actions include `fetchItems` to retrieve a range of items based on a reference ID, `initialize` to set up the queue upon a load request, and `nextItems`/`prevItems` to get items following or preceding a given item. Other methods handle updates like `onItemsInserted`, `onItemsRemoved`, `onItemsReordered`, and also manage playback order using `shuffle` and `unshuffle`. The `onCurrentItemIdChanged` method is called when an item is playing.\n"],null,["# Class: QueueBase\n\ncast.[framework](/cast/docs/reference/web_receiver/cast.framework).QueueBase\n============================================================================\n\nclass static\n\nBase implementation of a queue.\n\nConstructor\n-----------\n\n### QueueBase\n\nnew\nQueueBase()\n\nMethods\n-------\n\n### fetchItems\n\nfetchItems(itemId, nextCount, prevCount) returns (non-null Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem) or non-null Promise containing non-null Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem))\n\nFetches a window of items using the specified `itemID` as reference. This\nmethod is called by `MediaManager` when it needs more queue items, often\nstemming from a sender request. If either `nextCount` or `prevCount` are\nset, `fetchItems` will only return items after or before the reference\nitem. If both `nextCount` and `prevCount` are set, a window of items\nincluding `itemId` will be returned.\n\n| #### Parameter ||\n|-----------|---------------------------------------------------|\n| itemId | number The ID of the reference item. |\n| nextCount | number Number of items after the reference item. |\n| prevCount | number Number of items before the reference item. |\n\nReturns\n\n: `(non-null Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)` or non-null Promise containing non-null Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)`)`\n\n### initialize\n\ninitialize(requestData) returns ([cast.framework.messages.QueueData](/cast/docs/reference/web_receiver/cast.framework.messages.QueueData) or non-null Promise containing nullable [cast.framework.messages.QueueData](/cast/docs/reference/web_receiver/cast.framework.messages.QueueData))\n\nInitializes the queue with `requestData`. Called when the receiver\ngets a new `cast.framework.messages.Command.LOAD` request. If this returns or\nresolves to `null`, the default queueing implementation will create a queue\nbased on `queueData.items` or on the single media item in the `LOAD`\nrequest data.\n\n| #### Parameter ||\n|-------------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| requestData | [cast.framework.messages.LoadRequestData](/cast/docs/reference/web_receiver/cast.framework.messages.LoadRequestData) Value must not be null. |\n\nReturns\n\n: `(nullable `[cast.framework.messages.QueueData](/cast/docs/reference/web_receiver/cast.framework.messages.QueueData)` or non-null Promise containing nullable `[cast.framework.messages.QueueData](/cast/docs/reference/web_receiver/cast.framework.messages.QueueData)`)`\n\n### nextItems\n\nnextItems(itemId) returns (nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem) or non-null Promise containing nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem))\n\nReturns all items in the queue following `itemID`. This is called by\n`MediaManager`.\n\n| #### Parameter ||\n|--------|-----------------------------------------------|\n| itemId | Optional number The ID of the reference item. |\n\nReturns\n\n: `(nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)` or non-null Promise containing nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)`)`\n\n### onCurrentItemIdChanged\n\nonCurrentItemIdChanged(itemId)\n\nSets the current item to `itemId`. Called by `MediaManager`\nwhen it changes the currently-playing item.\n\n| #### Parameter ||\n|--------|------------------------------------|\n| itemId | number The unique ID for the item. |\n\n### onItemsInserted\n\nonItemsInserted(items, insertBefore)\n\nA callback that indicates that the following items have been inserted into\nthe receiver queue in this session. A cloud-based implementation might\nupdate its queue based on this new information.\n\n| #### Parameter ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| items | Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem) The items that were inserted. Value must not be null. |\n| insertBefore | Optional number ID of the item that was located immediately after the inserted list. If the ID is not provided, the inserted list was appended to the end of the queue. |\n\n### onItemsRemoved\n\nonItemsRemoved(itemIds)\n\nA callback that indicates that the following items have been removed from\nthe receiver queue in this session. A cloud-based implementation might\nupdate its queue based on this new information.\n\n| #### Parameter ||\n|---------|---------------------------------------------------------------------------------|\n| itemIds | Array of number The IDs of the items that were removed. Value must not be null. |\n\n### onItemsReordered\n\nonItemsReordered(items, insertBefore)\n\nA callback that indicates that the following items have been reordered.\n\n| #### Parameter ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| items | Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem) The IDs of the items that were reordered. Value must not be null. |\n| insertBefore | Optional number ID of the item that is located immediately after the reordered list. If `insertBefore` is not provided, the reordered list will be appended to the end of the queue. |\n\nSee also\n: [cast.framework.messages.QueueReorderRequestData#itemIds](/cast/docs/reference/web_receiver/cast.framework.messages.QueueReorderRequestData#itemIds) for more details.\n\n### prevItems\n\nprevItems(itemId) returns (nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem) or non-null Promise containing nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem))\n\nReturns all items before `itemID`. This is called by `MediaManager`.\n\n| #### Parameter ||\n|--------|-----------------------------------------------|\n| itemId | Optional number The ID of the reference item. |\n\nReturns\n\n: `(nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)` or non-null Promise containing nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)`)`\n\n### shuffle\n\nshuffle() returns (nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem) or non-null Promise containing nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem))\n\nShuffles the queue and returns new queue items. Returns `null` if the\noperation is not supported.\n\nReturns\n\n: `(nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)` or non-null Promise containing nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)`)`\n\n### unshuffle\n\nunshuffle() returns (nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem) or non-null Promise containing nullable Array of non-null [cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem))\n\nUnshuffles the queue and returns new queue items. Returns `null` if the\noperation is not supported.\n\nReturns\n\n: `(nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)` or non-null Promise containing nullable Array of non-null `[cast.framework.messages.QueueItem](/cast/docs/reference/web_receiver/cast.framework.messages.QueueItem)`)`"]]