chrome.cast.media. Media
Represents a media item that has been loaded into the receiver application.
Constructor
Media
new Media(sessionId, mediaSessionId)
Parameter |
|
---|---|
sessionId |
string The session identifier. |
mediaSessionId |
number The media identifier. |
Properties
activeTrackIds
nullable Array of number
List of IDs corresponding to the active Tracks.
breakStatus
(non-null chrome.cast.media.BreakStatus or undefined)
Status of a break when a break is playing on the receiver. This field will be defined when the receiver is playing a break, empty when a break is not playing, but is present in the content, and undefined if the content contains no breaks.
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
nullable 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.
liveSeekableRange
(non-null chrome.cast.media.LiveSeekableRange or undefined)
Seekable range of a live or event stream. It uses relative media time in seconds. It will be undefined for VOD streams.
loadingItemId
nullable number
Item ID of the item that is currently loading on the receiver. Null if no item is currently loading.
media
nullable 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).
queueData
(non-null chrome.cast.media.QueueData or undefined)
Queue data.
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.
videoInfo
(non-null chrome.cast.media.VideoInformation or undefined)
The video information.
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. |
getEstimatedBreakClipTime
getEstimatedBreakClipTime() returns (number or undefined)
Estimates the current break clip position based on the last information reported by the receiver.
- Returns
-
(number or undefined)
An estimate of the current break clip position in seconds since the start of the media. Will return undefined if breakStatus or currentBreakClipTime are not defined when a break is not playing.
getEstimatedBreakTime
getEstimatedBreakTime() returns (number or undefined)
Estimates the current break position based on the last information reported by the receiver.
- Returns
-
(number or undefined)
An estimate of the current break position in seconds since the start of the media. Will return undefined if breakStatus or currentBreakTime are not defined (when a break is not playing).
getEstimatedLiveSeekableRange
getEstimatedLiveSeekableRange() returns (chrome.cast.media.LiveSeekableRange or undefined)
Estimates the start of the liveSeekableRange in seconds based on the last information reported by the receiver.
- Returns
-
(non-null chrome.cast.media.LiveSeekableRange or undefined)
An estimate of the current liveSeekableRange. Will return undefined if liveSeekableRange, liveSeekableRange.start, or liveSeekableRange.end are not defined when the content is not live.
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 |
|
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 |
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 |
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. |
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. |
newIndex |
number The new index of the item. |
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. |
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 |
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 |
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 |
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.