cast.framework. PlayerManager
Controls and monitors media playback.
- Throws
-
non-null Error
If constructor is used directly. The PlayerManager should only be accessed by calling cast.framework.CastReceiverContext#getPlayerManager.
Methods
addEventListener
addEventListener(eventType, eventListener)
Adds an event listener for player event.
Parameter |
|
---|---|
eventType |
(non-null cast.framework.events.EventType or non-null Array of non-null cast.framework.events.EventType) An event type or array of event types |
eventListener |
function(non-null cast.framework.events.Event) |
- Throws
-
non-null Error
If given arguments are not valid.
addSupportedMediaCommands
addSupportedMediaCommands(supportedMediaCommands, broadcastStatus)
Add commands to receiver supported media commands.
Parameter |
|
---|---|
supportedMediaCommands |
number A bitmask of media commands supported by the application. |
broadcastStatus |
Optional boolean Whether the senders should be notified about the change (if not provided, the senders will be notified). |
- See also
- cast.framework.messages.Command
broadcastStatus
broadcastStatus(includeMedia, requestId, customData, includeQueueItems)
Sends a media status message to all senders (broadcast). Applications use this to send a custom state change.
Parameter |
|
---|---|
includeMedia |
Optional boolean Whether to include media information. |
requestId |
Optional number The ID of the incoming request that caused this response. |
customData |
Optional Object The status message application-specific custom data. Value may be null. |
includeQueueItems |
Optional boolean Whether to include queue items in the status message. By default they are not included. |
getAbsoluteTimeForMediaTime
getAbsoluteTimeForMediaTime(mediaTime) returns number
Convert media time to absolute time.
Parameter |
|
---|---|
mediaTime |
number Media time. |
- Returns
-
nullable number
absolute time or null if not available.
getAudioTracksManager
getAudioTracksManager() returns cast.framework.AudioTracksManager
- Returns
-
non-null cast.framework.AudioTracksManager
getBreakClipCurrentTimeSec
getBreakClipCurrentTimeSec() returns number
Returns current time in sec in currently-playing break clip.
- Returns
-
nullable number
Current time in sec inside current break clip. Null, if player is not playing break clip.
getBreakClipDurationSec
getBreakClipDurationSec() returns number
Returns duration in sec of currently-playing break clip.
- Returns
-
nullable number
Duration of current break clip. Null, if player is not playing break clip.
getBreakManager
getBreakManager() returns cast.framework.breaks.BreakManager
Obtain the breaks (Ads) manager.
- Returns
-
non-null cast.framework.breaks.BreakManager
getBreaks
getBreaks() returns Array of non-null cast.framework.messages.Break
Returns list of breaks.
- Returns
-
non-null Array of non-null cast.framework.messages.Break
getCurrentSupportedMediaCommands
getCurrentSupportedMediaCommands() returns number
Gets the current receiver supported media commands. Should only be called after calling receiver start, otherwise it returns 0. This reflects the current media status. E.g. during ads playback, SEEK might not be supported.
- See also
- cast.framework.messages.Command
- Returns
-
number
A bitmask of media commands supported by the application.
getCurrentTimeSec
getCurrentTimeSec() returns number
Gets current time in sec of current media.
- Returns
-
number
Current time of media. 0 if there is no media playing.
getDurationSec
getDurationSec() returns number
Gets duration in sec of currently playing media.
- Returns
-
number
Duration of media. NaN if there is no media playing.
getLiveSeekableRange
getLiveSeekableRange() returns cast.framework.messages.LiveSeekableRange
Returns live seekable range with start and end time in seconds. The values are media time based.
- Returns
getMediaInformation
getMediaInformation() returns cast.framework.messages.MediaInformation
Gets media information of current media.
- Returns
getMediaTimeForAbsoluteTime
getMediaTimeForAbsoluteTime(absoluteTime) returns number
Convert absolute time to media time.
Parameter |
|
---|---|
absoluteTime |
number Media time. |
- Returns
-
nullable number
media time or null if not available.
getPlaybackConfig
getPlaybackConfig() returns cast.framework.PlaybackConfig
Returns playback configuration.
- Returns
-
nullable cast.framework.PlaybackConfig
getPlaybackRate
getPlaybackRate() returns number
Returns current playback rate. Returns 1 before receiver start is called.
- Returns
-
number
Current playback rate.
getPlayerState
getPlayerState() returns cast.framework.messages.PlayerState
Gets player state.
- Returns
-
non-null cast.framework.messages.PlayerState
PlayerState of current player.
getPreferredPlaybackRate
getPreferredPlaybackRate() returns number
Get the preferred playback rate. (Can be used on shutdown event to save latest preferred playback rate to a persistent storage, so it can be used in next session in the cast options).
- Returns
-
number
getPreferredTextLanguage
getPreferredTextLanguage() returns string
Get the preferred text track language.
- Returns
-
nullable string
getPreferredTextStyle
getPreferredTextStyle() returns cast.framework.messages.TextTrackStyle
Get the preferred text track style.
- Returns
getQueueManager
getQueueManager() returns (cast.framework.QueueManager or undefined)
Obtain QueueManager API.
- Returns
-
(non-null cast.framework.QueueManager or undefined)
getStartAbsoluteTime
getStartAbsoluteTime() returns number
Gets media start time in absolute time for live.
- Returns
-
nullable number
getStats
getStats() returns cast.framework.Stats
Returns stats about playback. Stats are aggregated over the entire playback session where appropriate.
- Returns
-
non-null cast.framework.Stats
getSupportedMediaCommands
getSupportedMediaCommands() returns number
Gets receiver supported media commands. Should only be called after calling receiver start, otherwise it returns 0. This is the static supported media commands set by receiver application. It won't be updated based on current media status.
- See also
- cast.framework.messages.Command
- Returns
-
number
A bitmask of media commands supported by the application.
getTextTracksManager
getTextTracksManager() returns cast.framework.TextTracksManager
- Returns
-
non-null cast.framework.TextTracksManager
getTimedMetadata
getTimedMetadata() returns Array of non-null cast.framework.TimedMetadata
Returns timed metadata encountered during manifest parsing. This is #EXT-X-DATERANGE in HLS and EventStream in DASH.
- Returns
-
non-null Array of non-null cast.framework.TimedMetadata
load
load(loadRequest) returns Promise containing void
Loads media.
Parameter |
|
---|---|
loadRequest |
cast.framework.messages.LoadRequestData A request to load a media. Value must not be null. |
- Returns
-
non-null Promise containing void
Promise that is resolved when operation succeded, or rejected if failed.
pause
pause()
Pauses currently playing media.
play
play()
Plays currently paused media.
playString
playString(stringId, args) returns Promise containing nullable cast.framework.messages.ErrorData
Requests a text string to be played back locally on the receiver device.
Parameter |
|
---|---|
stringId |
cast.framework.messages.PlayStringId An identifier for the text to be played back. Value must not be null. |
args |
Optional Array of string An optional array of string values to be filled into the text. Value must not be null. |
- Returns
-
non-null Promise containing nullable cast.framework.messages.ErrorData
refreshCredentials
refreshCredentials() returns Promise containing void
Request Google Assistant to refresh the credentials. Only works if the original credentials came from the assistant.
- Returns
-
non-null Promise containing void
Promise that resolved once new set credentials message is received, or rejected on error.
removeEventListener
removeEventListener(eventType, eventListener)
Removes the event listener added for given player event. If event listener is not added, it will be ignored.
Parameter |
|
---|---|
eventType |
(non-null cast.framework.events.EventType or non-null Array of non-null cast.framework.events.EventType) An eventType or array of event types |
eventListener |
function(non-null cast.framework.events.Event) |
removeSupportedMediaCommands
removeSupportedMediaCommands(supportedMediaCommands, broadcastStatus)
Remove commands from receiver supported media commands.
Parameter |
|
---|---|
supportedMediaCommands |
number A bitmask of media commands supported by the application. |
broadcastStatus |
Optional boolean Whether the senders should be notified about the change (if not provided, the senders will be notified). |
- See also
- cast.framework.messages.Command
seek
seek(seekTime)
Seeks in current media.
Parameter |
|
---|---|
seekTime |
number |
sendCustomState
sendCustomState(state)
Send a custom state to UI from playback logic. This should be used to separate the playback logic and UI logic, To allow the same UI logic to be used for loacal payback and remote control. The custom state will be available to the UI through player data.
Parameter |
|
---|---|
state |
Object Custom state object. Value must not be null. |
sendError
sendError(senderId, requestId, type, reason, customData)
Sends an error to a specific sender.
Parameter |
|
---|---|
senderId |
string The sender ID. |
requestId |
number The ID of the incoming request that caused this error. |
type |
cast.framework.messages.ErrorType The error type. Value must not be null. |
reason |
Optional cast.framework.messages.ErrorReason The error reason. Value may be null. |
customData |
Optional Object The error message application-specific custom data. Value may be null. |
sendLocalMediaRequest
sendLocalMediaRequest(request)
Send local media request.
Parameter |
|
---|---|
request |
cast.framework.messages.RequestData Value must not be null. |
sendStatus
sendStatus(senderId, requestId, includeMedia, customData, includeQueueItems)
Sends a media status message to a specific sender.
Parameter |
|
---|---|
senderId |
string The sender ID. |
requestId |
number The ID of the incoming request that caused this response. |
includeMedia |
Optional boolean Whether to include media information. |
customData |
Optional Object The status message application-specific custom data. Value may be null. |
includeQueueItems |
Optional boolean Whether to include queue items in the status message. By default they are not included. |
setIdleReason
setIdleReason(idleReason)
Sets the IDLE reason. This allows applications that want to force the IDLE state to indicate the reason that made the player going to IDLE state (a custom error, for example). The idle reason will be sent in the next status message. NOTE: Most applications do not need to set this value, it is only needed if they want to make the player go to IDLE in special circumstances and the default idleReason does not reflect their intended behavior.
Parameter |
|
---|---|
idleReason |
cast.framework.messages.IdleReason The reason to be in the IDLE state. Value must not be null. |
setMediaElement
setMediaElement(mediaElement)
Sets MediaElement to use. If Promise of MediaElement is set, media begins playback after Promise is resolved.
Parameter |
|
---|---|
mediaElement |
(non-null HTMLMediaElement or non-null Promise containing non-null HTMLMediaElement) MediaElement that player will use. |
setMediaInformation
setMediaInformation(mediaInformation, opt_broadcast)
Sets media information.
Parameter |
|
---|---|
mediaInformation |
cast.framework.messages.MediaInformation Value must not be null. |
opt_broadcast |
Optional boolean |
setMediaPlaybackInfoHandler
setMediaPlaybackInfoHandler(handler)
Sets a handler to return or modify cast.framework.PlaybackConfig, for a specific load request. The handler paramaters are the load request data and default playback config for the receiver (provided in the context options). The handler should returns a modified playback config, or null to prevent the media from playing. The return value can be a promise to allow waiting for data from the server.
Parameter |
|
---|---|
handler |
function(non-null cast.framework.messages.LoadRequestData, non-null cast.framework.PlaybackConfig) A function to provide a request specific playback config. Value may be null. |
setMediaUrlResolver
setMediaUrlResolver(resolver)
Sets a handler to return the media url for a load request. This handler can be used to avoid having the media content url published as part of the media status. By default the media contentId is used as the content url.
Parameter |
|
---|---|
resolver |
function(non-null cast.framework.messages.LoadRequestData) A function to resolve media content url. Value may be null. |
setMessageInterceptor
setMessageInterceptor(type, interceptor)
Provide an interceptor of incoming and outgoing messages. The interceptor can update the request data, and return updated data, a promise of updated data if need to get more data from the server, or null if the request should not be handled. Note that if load message interceptor is provided, and no interceptor is provided for preload - the load interceptor will be called for preload messages.
Parameter |
|
---|---|
type |
cast.framework.messages.MessageType Value must not be null. |
interceptor |
function(non-null cast.framework.messages.RequestData) Value may be null. |
setPlaybackConfig
setPlaybackConfig(playbackConfig)
Sets playback configuration on the PlayerManager.
Parameter |
|
---|---|
playbackConfig |
Value must not be null. |
setSupportedMediaCommands
setSupportedMediaCommands(supportedMediaCommands, broadcastStatus)
Set receiver supported media commands.
Parameter |
|
---|---|
supportedMediaCommands |
number A bitmask of media commands supported by the application. |
broadcastStatus |
Optional boolean Whether the senders should be notified about the change (if not provided, the senders will be notified). |
- See also
- cast.framework.messages.Command
stop
stop()
Stops currently playing media.