Constructor

Media

new Media(sessionId, mediaSessionId)

Represents a media item that has been loaded into the receiver application.

Parameter

sessionId

string

The session identifier.

mediaSessionId

number

The media identifier.

Properties

activeTrackIds

Array of number

List of IDs corresponding to the active Tracks.

currentItemId

nullable number

Item ID of the item that was active in the queue (it may not be playing) at the time the media status change happened.

currentTime

number

The current playback position in seconds since the start of the media. This member is only updated sporadically, so its value is often out of date. Use the getEstimatedTime method to get an estimate of the real playback position based on the last information reported by the receiver.

Deprecated
Use getEstimatedTime instead.

customData

Object

Custom data set by the receiver application.

idleReason

nullable chrome.cast.media.IdleReason

Idle reason if receiver knows.

items

nullable Array of non-null chrome.cast.media.QueueItem

Array of sorted items in the queue.

loadingItemId

nullable number

Item ID of the item that is currently loading on the receiver. Null if no item is currently loading.

media

chrome.cast.media.MediaInfo

Media description.

mediaSessionId

number

Identifies the media item.

playbackRate

number

The playback rate. 1.0 represents normal playback.

playerState

non-null chrome.cast.media.PlayerState

The player state.

preloadedItemId

nullable number

ID of the next Item, only available if it has been preloaded. On the receiver media items can be preloaded and cached temporarily in memory, so when they are loaded later on, the process is faster (as the media does not have to be fetched from the network).

repeatMode

non-null chrome.cast.media.RepeatMode

The repeat mode for playing the queue.

sessionId

string

Identifies the session that is hosting the media.

supportedMediaCommands

non-null Array of non-null chrome.cast.media.MediaCommand

The media commands supported by the media player.

volume

non-null chrome.cast.Volume

The media stream volume. volume.level and volume.muted will always be set.

Methods

addUpdateListener

addUpdateListener(listener)

Adds a listener that is invoked when the status of the media has changed. Changes to the following properties will trigger the listener: currentTime, volume, metadata, playbackRate, playerState, customData. A successful call to the media's getStatus method will also trigger the listener.

Parameter

listener

function(boolean)

The listener to add. The parameter indicates whether the Media object is still alive.

editTracksInfo

editTracksInfo(editTracksInfoRequest, successCallback, errorCallback)

Modifies the text tracks style or change the tracks status. If a trackId does not match the existing trackIds the whole request will fail and no status will change.

Parameter

editTracksInfoRequest

chrome.cast.media.EditTracksInfoRequest

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

getEstimatedTime

getEstimatedTime() returns number

Estimates the current playback position based on the last information reported by the receiver.

Returns

number An estimate of the current playback position in seconds since the start of the media.

getStatus

getStatus(getStatusRequest, successCallback, errorCallback)

Gets the status of the media item from the receiver application.

Along with the given successCallback, any added media update listeners will also be invoked when the status is received from the receiver application. Instead of calling this method to poll the media status, apps should prefer relying on the automatic invocation of media update listeners whenever the media changes.

Parameter

getStatusRequest

chrome.cast.media.GetStatusRequest

The optional get status request.

successCallback

function()

Invoked when the status is received from the receiver application.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

pause

pause(pauseRequest, successCallback, errorCallback)

Pauses the media item.

Parameter

pauseRequest

chrome.cast.media.PauseRequest

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The media pause request. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

play

play(playRequest, successCallback, errorCallback)

Plays the media item.

Parameter

playRequest

chrome.cast.media.PlayRequest

The optional media play request.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueAppendItem

queueAppendItem(item, successCallback, errorCallback)

Appends a new media item to the end of the queue.

Parameter

item

chrome.cast.media.QueueItem

Item to append to the end of the queue.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueInsertItems

queueInsertItems(queueInsertItemsRequest, successCallback, errorCallback)

Inserts a list of new media items into the queue.

Parameter

queueInsertItemsRequest

chrome.cast.media.QueueInsertItemsRequest

Request to insert media items into the media queue.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueJumpToItem

queueJumpToItem(itemId, successCallback, errorCallback)

Plays the item with itemId in the queue.

If itemId is not found in the queue, either because it wasn't there originally or it was removed by another sender before calling this function, this function will silently return without sending a request to the receiver.

Parameter

itemId

number

The ID of the item to which to jump.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueMoveItemToNewIndex

queueMoveItemToNewIndex(itemId, newIndex, successCallback, errorCallback)

Moves the item with itemId to be at position newIndex in the queue.

If itemId is not found in the queue, either because it wasn't there originally or it was removed by another sender before calling this function, this function will silently return without sending a request to the receiver.

errorCallback will be invoked if newIndex is negative. However if newIndex overflows, either because it was wrongly specified or the queue was shrunk by another sender, the item will be moved to the end of the queue.

Parameter

itemId

number

The ID of the item to be moved.

Value must not be null.

newIndex

number

The new index of the item.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueNext

queueNext(successCallback, errorCallback)

Jumps to the next item in the queue.

Parameter

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queuePrev

queuePrev(successCallback, errorCallback)

Jumps to the previous item in the queue.

Parameter

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueRemoveItem

queueRemoveItem(itemId, successCallback, errorCallback)

Removes the item with itemId from the queue.

If itemId is not found in the queue, either because it wasn't there originally or it was removed by another sender before calling this function, this function will silently return without sending a request to the receiver.

Parameter

itemId

number

The ID of the item to be removed.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueReorderItems

queueReorderItems(queueReorderItemsRequest, successCallback, errorCallback)

Reorder a list of media items in the queue.

Parameter

queueReorderItemsRequest

chrome.cast.media.QueueReorderItemsRequest

Request to reorder items in the media queue.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueSetRepeatMode

queueSetRepeatMode(repeatMode, successCallback, errorCallback)

Sets the repeat mode of the queue.

Parameter

repeatMode

chrome.cast.media.RepeatMode

The algorithm for selection of the next item when the current item has ended.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

queueUpdateItems

queueUpdateItems(queueUpdateItemsRequest, successCallback, errorCallback)

Updates properties of the media queue, e.g. repeat mode, and properties of the existing items in the media queue.

Parameter

queueUpdateItemsRequest

chrome.cast.media.QueueUpdateItemsRequest

Request to update the properties of the media queue.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

removeUpdateListener

removeUpdateListener(listener)

Removes a previously added listener for this Media.

Parameter

listener

function(boolean)

The listener to remove.

seek

seek(seekRequest, successCallback, errorCallback)

Seeks the media item.

Parameter

seekRequest

chrome.cast.media.SeekRequest

The media seek request.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

setVolume

setVolume(volumeRequest, successCallback, errorCallback)

Sets the media stream volume. At least one of volumeRequest.level or volumeRequest.muted must be set. Changing the mute state does not affect the volume level, and vice versa.

Parameter

volumeRequest

chrome.cast.media.VolumeRequest

The set volume request.

Value must not be null.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

stop

stop(stopRequest, successCallback, errorCallback)

Stops the media player.

Parameter

stopRequest

chrome.cast.media.StopRequest

The stop request.

successCallback

function()

Invoked on success.

errorCallback

function(non-null chrome.cast.Error)

Invoked on error. The possible errors are TIMEOUT, API_NOT_INITIALIZED, INVALID_PARAMETER, CHANNEL_ERROR, SESSION_ERROR, and EXTENSION_MISSING.

supportsCommand

supportsCommand(command) returns boolean

Determines whether the media player supports the given media command.

Parameter

command

chrome.cast.media.MediaCommand

The command to query.

Value must not be null.

Returns

boolean True if the player supports the command.