Autoplay & Queueing APIs

Autoplay allows the user to continue playing content in a playlist or a series of related media without taking action, and it provides for content preloading. You can implement an autoplay UI with or without using the Cast queueing APIs.

The Cast queueing APIs allow users to create lists of content items, such as video or audio streams, to play sequentially on the Cast receiver. The queue of content items may be edited, reordered, updated, and so forth. This document describes how to implement an autoplay UI that uses the queueing APIs.

The Cast Receiver SDK maintains the queue and responds to operations on the queue as long as the queue has at least one item currently active (playing or paused). Senders can join the session and add items to the queue. The receiver maintains a session for queue items until the last item completes playback or the sender stops the playback and terminates the session, or until a sender loads a new queue on the receiver. The receiver does not maintain any information about terminated queues by default. Once the last item in the queue finishes, the media session ends and the queue vanishes.

Sender API

Create and load media queue items

A media queue item is represented in the Cast SDK as follows:

When you create a media queue item, if you are using the Media Player Library with adaptive content, you can set the preload time so that the player can begin buffering the media queue item before the item ahead of it in the queue finishes playing. Setting the item's autoplay attribute to true allows the receiver to play it automatically. For example, you can use a builder pattern to create your media queue item as follows:

MediaQueueItem queueItem = new MediaQueueItem.Builder(mediaInfo)

Load an array of media queue items in the queue by using the appropriate load method:

Media queue status

When the receiver loads a media queue item, it assigns a unique ID to the item which persists for the duration of the session (and the life of the queue). You can learn the status of the queue in terms of which item is currently loaded (it may not be playing), loading, or preloaded. You can also get an ordered list of all the items in the queue. The following APIs provide this information:

API Preloaded Loading Current All items
Android getPreloadedItemId getLoadingItemId getCurrentItemId getQueueItems
Chrome preloadedItemId loadingItemId currentItemId items
iOS preloadedItemID loadingItemID currentItemID queueItemCount and

Use these APIs together with the other media status APIs to inform your app about the status of the queue and the items in the queue. For example, when the last item has finished, the player's IdleReason (in Chrome) is FINISHED. In addition to media status updates from the receiver, you can listen for changes to the queue by implementing the following listeners or callbacks:

Edit the queue

To work with the items in the queue, you have several APIs. These let you load an array of items into a new queue, insert items into an existing queue, update the properties of items in the queue, make an item jump forward or backward in the queue, set the properties of the queue itself (for example, change the repeatMode algorithim that selects the next item), remove items from the queue, and reorder the items in the queue. See the following APIs:

Queueing on a receiver

To see how to use the CAF Receiver SDK to implement queueing, see Queueing.

To see how to use the old Custom Receiver v2 SDK to implement queueing, see Queueing.