# cast.[framework](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework).PlayerManager

class static

Controls and monitors media playback.

Throws

:   `non-null Error` If constructor is used directly.
    `PlayerManager` should only be accessed
    by calling [cast.framework.CastReceiverContext#getPlayerManager](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.CastReceiverContext#getPlayerManager).

## Methods

### addEventListener

addEventListener(eventType, eventListener)

Adds an event listener that listens for playback events.

| #### Parameter ||
|---|---|
| eventType | (non-null [cast.framework.events.EventType](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.events#.EventType) or non-null Array of non-null [cast.framework.events.EventType](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.events#.EventType)) An event type or array of event types |
| eventListener | function(non-null [cast.framework.events.Event](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.events.Event)) |

Throws

:   `non-null Error` If given arguments are not valid.

### addSupportedMediaCommands

addSupportedMediaCommands(supportedMediaCommands, broadcastStatus)

Adds new supported commands to the existing list of supported media
commands.

| #### Parameter ||
|---|---|
| supportedMediaCommands | number A bitmask of media commands supported by the application. |
| broadcastStatus | Optional boolean `true` indicates that the senders should be notified about the change (if not provided, the senders will be notified). |

See also
:   [cast.framework.messages.Command](https://developers.google.com/cast/docs/reference/web_receiver/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 `true` indicates the message should 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

Converts media time to media absolute time.
Absolute time is applicable only for live streams.

| #### Parameter ||
|---|---|
| mediaTime | number Media time. |

Returns

:   `nullable number` Absolute time or `null` if not available.

### getAudioTracksManager

getAudioTracksManager() returns [cast.framework.AudioTracksManager](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.AudioTracksManager)

Gets the `AudioTracksManager` instance.

Returns

:   `non-null https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.AudioTracksManager`

### getBreakClipCurrentTimeSec

getBreakClipCurrentTimeSec() returns number

Returns current time of the currently-playing break clip, in seconds.

Returns

:   `nullable number` Current time in seconds inside current break clip.
    `null` when the `Player` is not playing break clip.

### getBreakClipDurationSec

getBreakClipDurationSec() returns number

Returns duration of the currently-playing break clip in seconds.

Returns

:   `nullable number` Duration of the current break clip.
    `null` when the `Player` is not playing a break clip.

### getBreakManager

getBreakManager() returns [cast.framework.breaks.BreakManager](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.breaks.BreakManager)

Gets the `BreakManager` instance.

Returns

:   `non-null https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.breaks.BreakManager`

### getBreaks

getBreaks() returns Array of non-null [cast.framework.messages.Break](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.Break)

Returns a list of breaks.

Returns

:   `non-null Array of non-null https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.Break`

### getCurrentSupportedMediaCommands

getCurrentSupportedMediaCommands() returns number

Gets the current receiver supported media commands.
Unlike for `getSupportedMediaCommands()`, the returned value of this method
changes dynamically based on the current playback status. For example,
during ads playback, the `SEEK` command might not be supported.
This method should only be called after calling receiver
`CastReceiverContext#start`, otherwise it will return `0`.

See also
:   [cast.framework.messages.Command](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.Command)

Returns

:   `number` A bitmask of media commands supported by the application.

### getCurrentTimeSec

getCurrentTimeSec() returns number

Gets the elapsed play time of the current media.

Returns

:   `number` The elapsed time, in seconds. This will be `0` if no media
    is playing.

### getDurationSec

getDurationSec() returns number

Gets the duration of the currently-playing media, in seconds.

Returns

:   `number` Duration of media. `NaN` if there is no media
    playing.

### getLiveSeekableRange

getLiveSeekableRange() returns [cast.framework.messages.LiveSeekableRange](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.LiveSeekableRange)

Returns the live seekable range with start time and end time in seconds.
The values are based on media time.

Returns

:   `nullable https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.LiveSeekableRange`

### getMediaInformation

getMediaInformation() returns [cast.framework.messages.MediaInformation](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.MediaInformation)

Gets media information of current media.

Returns

:   `nullable https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.MediaInformation`

### getMediaTimeForAbsoluteTime

getMediaTimeForAbsoluteTime(absoluteTime) returns number

Converts the media absolute time to media time. Absolute time is
applicable only for live streams.

| #### Parameter ||
|---|---|
| absoluteTime | number The media's absolute time, as UNIX Epoch time (seconds since the Unix epoch). |

Returns

:   `nullable number` Media time or `null` if not available.

### getPlaybackConfig

getPlaybackConfig() returns [cast.framework.PlaybackConfig](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.PlaybackConfig)

Returns playback configuration or `null` if the defaults haven't been
overridden.

Returns

:   `nullable https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.PlaybackConfig`

### getPlaybackRate

getPlaybackRate() returns number

Returns the current playback rate.
Returns `1` before receiver `CastReceiverContext#start` is called.

Returns

:   `number` Current playback rate.

### getPlayerState

getPlayerState() returns [cast.framework.messages.PlayerState](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.PlayerState)

Gets the `Player` state.

Returns

:   `non-null https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.PlayerState` The state of the current
    `Player`.

### getPreferredPlaybackRate

getPreferredPlaybackRate() returns number

Get the preferred playback rate.
Can be used on shutdown event to save the latest preferred playback rate
to persistent storage, so it can be used in next session in the cast
options.

Returns

:   `number`

### getPreferredTextLanguage

getPreferredTextLanguage() returns string

Gets the preferred text track language.

Returns

:   `nullable string`

### getPreferredTextStyle

getPreferredTextStyle() returns [cast.framework.messages.TextTrackStyle](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.TextTrackStyle)

Gets the preferred text track style.

Returns

:   `nullable https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.TextTrackStyle`

### getQueueManager

getQueueManager() returns ([cast.framework.QueueManager](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.QueueManager) or undefined)

Gets the `QueueManager` instance.

Returns

:   `(non-null https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.QueueManager or undefined)`

### getRawCurrentTimeSec

getRawCurrentTimeSec() returns number

Gets the elapsed play time of the current media, without subtracting the ad
break time.

Returns

:   `number` The elapsed time, in seconds. This will be `0` if no media
    is playing.

### getRawSeekableRange

getRawSeekableRange() returns cast.framework.messages.Range

Returns the current media seekable range.

NOTE: This matches the units of `getRawCurrentTimeSec()`, but not
`seek()`!. This does not account for ads or any other media offsets.
Unless you are sure you need the raw values, you should be using
`getLiveSeekableRange()` instead.

Returns

:   `nullable cast.framework.messages.Range`

### getStartAbsoluteTime

getStartAbsoluteTime() returns number

Gets the absolute media start time, as
UNIX Epoch time (seconds since the Unix epoch).
Absolute time is applicable only for live streams.

Returns

:   `nullable number`

### getStats

getStats() returns [cast.framework.stats.Stats](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.stats.Stats)

Returns playback statistics. Statistics are aggregated over the entire
playback session where appropriate.

Returns

:   `non-null https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.stats.Stats`

### getSupportedMediaCommands

getSupportedMediaCommands() returns number

Gets receiver supported media commands. Should only be called after calling
`CastReceiverContext#start()`, otherwise it returns `0`. The supported
media commands value is controlled solely by the receiver application .
It's not automatically updated based on a `MediaStatus`.

See also
:   [cast.framework.messages.Command](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.Command)

Returns

:   `number` A bitmask of media commands supported by the application.

### getTextTracksManager

getTextTracksManager() returns [cast.framework.TextTracksManager](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.TextTracksManager)

Gets the `TextTracksManager` instance.

Returns

:   `non-null https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.TextTracksManager`

### getTimedMetadata

getTimedMetadata() returns Array of non-null [cast.framework.TimedMetadata](https://developers.google.com/cast/docs/reference/web_receiver/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 https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.TimedMetadata`

### load

load(loadRequest) returns Promise containing void

Initiates a request to load media.

| #### Parameter ||
|---|---|
| loadRequest | [cast.framework.messages.LoadRequestData](https://developers.google.com/cast/docs/reference/web_receiver/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 succeeded,
    or rejected if failed.

### pause

pause()

Pauses the currently-playing media.

### play

play()

Plays the currently-paused media.

### removeEventListener

removeEventListener(eventType, eventListener)

Removes the event listener added for a given playback event.
If no matching event listener exists, this call is ignored.

| #### Parameter ||
|---|---|
| eventType | (non-null [cast.framework.events.EventType](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.events#.EventType) or non-null Array of non-null [cast.framework.events.EventType](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.events#.EventType)) An eventType or array of event types |
| eventListener | function(non-null [cast.framework.events.Event](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.events.Event)) |

### removeSupportedMediaCommands

removeSupportedMediaCommands(supportedMediaCommands, broadcastStatus)

Remove commands from the list of supported media commands.

| #### Parameter ||
|---|---|
| supportedMediaCommands | number A bitmask of media commands supported by the application. |
| broadcastStatus | Optional boolean `true` indicates that the senders should be notified about the change (if not provided, the senders will be notified). |

See also
:   [cast.framework.messages.Command](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.Command)

### seek

seek(seekTime)

Seeks in current media.

| #### Parameter ||
|---|---|
| seekTime | number |

### sendCustomState

sendCustomState(state)

Sends a custom state from an application playback logic to the UI logic.
This method helps enable separation of playback logic and UI.
Maintaining separation between logic and UI permits one to use the same
UI logic for both local playback and remote control.
The custom state sent by this method is available to the UI through
`PlayerData`.

| #### Parameter ||
|---|---|
| state | Object Custom state object. Value must not be null. |

See also
:   [cast.framework.ui.PlayerData#customState](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.ui.PlayerData#customState)

### 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](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.ErrorType) The error type. Value must not be null. |
| reason | Optional [cast.framework.messages.ErrorReason](https://developers.google.com/cast/docs/reference/web_receiver/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)

Sends a local media request.

| #### Parameter ||
|---|---|
| request | [cast.framework.messages.RequestData](https://developers.google.com/cast/docs/reference/web_receiver/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 `true` indicates the message should include a `MediaInformation` instance. |
| 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 reason for the player being in the `IDLE` state.
This allows applications that want to force the `IDLE`
state to indicate the reason for doing so (for example, a custom error).
The idle reason is sent in the next status message.
**Note** Most applications do not need to set this value. It is only needed
if the app needs to make the `Player` go to the `IDLE` state in special
circumstances and the default idleReason does not reflect the intended
behavior.

| #### Parameter ||
|---|---|
| idleReason | [cast.framework.messages.IdleReason](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.IdleReason) The reason to be in the `IDLE` state. Value must not be null. |

### setMediaElement

setMediaElement(mediaElement)

Sets the `HTMLMediaElement` to use. If a `Promise` of a
`HTMLMediaElement` is set, media begins playback after the `Promise` is
resolved.

| #### Parameter ||
|---|---|
| mediaElement | (non-null HTMLMediaElement or non-null Promise containing non-null HTMLMediaElement) `MediaElement` that the `Player` will use. |

### setMediaInformation

setMediaInformation(mediaInformation, opt_broadcast)

Sets media information.

| #### Parameter ||
|---|---|
| mediaInformation | [cast.framework.messages.MediaInformation](https://developers.google.com/cast/docs/reference/web_receiver/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](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.PlaybackConfig),
for a specific load request. The handler parameters are the
`LoadRequestData` and default `PlaybackConfig` for the receiver (provided
in the `CastReceiverOptions`). The handler should return a modified
playback config, or `null` to prevent the media from playing. The return
value may also be a `Promise` to allow waiting for data from the server.

| #### Parameter ||
|---|---|
| handler | function(non-null [cast.framework.messages.LoadRequestData](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.LoadRequestData), non-null [cast.framework.PlaybackConfig](https://developers.google.com/cast/docs/reference/web_receiver/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](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.LoadRequestData)) A function to resolve media content URL. Value may be null. |

### setMessageInterceptor

setMessageInterceptor(type, interceptor)

Sets an interceptor of incoming and outgoing messages.
The interceptor can update the request data, and should return either
updated data, a `Promise` with updated data (if data cannot be returned
immediately), or `null` if the request should not be handled.
*Note* : if a `LOAD` message interceptor is provided, but no separate
`PRELOAD` interceptor is provided, the `LOAD` interceptor will be called
for `PRELOAD` messages.

| #### Parameter ||
|---|---|
| type | [cast.framework.messages.MessageType](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.MessageType) Value must not be null. |
| interceptor | function(non-null [cast.framework.messages.RequestData](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.RequestData)) Value may be null. |

Throws

:   `non-null Error` If the message type is invalid, or if the interceptor is
    not a function.

### setPlaybackConfig

setPlaybackConfig(playbackConfig)

Sets playback configuration on the `PlayerManager`.

| #### Parameter ||
|---|---|
| playbackConfig | [cast.framework.PlaybackConfig](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.PlaybackConfig) Value must not be null. |

### setSupportedMediaCommands

setSupportedMediaCommands(supportedMediaCommands, broadcastStatus)

Sets the media commands supported by the receiver.

| #### Parameter ||
|---|---|
| supportedMediaCommands | number A bitmask of media commands supported by the application. |
| broadcastStatus | Optional boolean `true` indicates that the senders should be notified about the change (if not provided, the senders will be notified). |

See also
:   [cast.framework.messages.Command](https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages#.Command)

### stop

stop()

Stops the currently-playing media.