RemoteMediaClient
Class for controlling a media player application running on a Cast receiver.
see
Android | iOS GCKRemoteMediaClient | Chrome RemotePlayer
example
import { useRemoteMediaClient } from 'react-native-google-cast'
function MyComponent() {
const client = useRemoteMediaClient()
if (client) {
// ...
}
}
Hierarchy
- RemoteMediaClient
Index
Properties
Methods
- getMediaStatus
- getStreamPosition
- loadMedia
- onMediaPlaybackEnded
- onMediaPlaybackStarted
- onMediaProgressUpdated
- onMediaStatusUpdated
- pause
- play
- queueInsertAndPlayItem
- queueInsertItem
- queueInsertItems
- queueNext
- queuePrev
- requestStatus
- seek
- setActiveMediaTracks
- setActiveTrackIds
- setPlaybackRate
- setStreamMuted
- setStreamVolume
- setTextTrackStyle
- stop
Properties
Private
Optional
progressUpdateListener
• progressUpdateListener? : EmitterSubscription
Methods
getMediaStatus
▸ getMediaStatus(): Promise‹MediaStatus | null›
The current media status, or null
if there isn't a media session.
Returns: Promise‹MediaStatus | null›
getStreamPosition
▸ getStreamPosition(): Promise‹number | null›
The current stream position, or null
if there isn't a media session.
Returns: Promise‹number | null›
loadMedia
▸ loadMedia(request
: MediaLoadRequest): Promise‹void›
Loads and starts playback of a media item or a queue of media items with a request data.
example
client.loadMedia({
autoplay: true,
mediaInfo: {
contentUrl: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/BigBuckBunny.mp4',
}
})
Parameters:
Name | Type |
---|---|
request | MediaLoadRequest |
Returns: Promise‹void›
onMediaPlaybackEnded
▸ onMediaPlaybackEnded(handler
: function): EmitterSubscription
Called when finished playback of an item.
Parameters:
▪ handler: function
▸ (mediaStatus
: MediaStatus | null): void
Parameters:
Name | Type |
---|---|
mediaStatus | MediaStatus | null |
Returns: EmitterSubscription
onMediaPlaybackStarted
▸ onMediaPlaybackStarted(handler
: function): EmitterSubscription
Called when started playback of an item.
Parameters:
▪ handler: function
▸ (mediaStatus
: MediaStatus | null): void
Parameters:
Name | Type |
---|---|
mediaStatus | MediaStatus | null |
Returns: EmitterSubscription
onMediaProgressUpdated
▸ onMediaProgressUpdated(handler
: function, interval
: number): object
Listen for updates on the progress of the currently playing media. Only one listener can be attached; when you attach another listener, the previous one will be removed. All times are in seconds.
Parameters:
▪ handler: function
called when progress or duration of the currently playing media changes.
▸ (progress
: number, duration
: number): void
Parameters:
Name | Type |
---|---|
progress | number |
duration | number |
▪Default value
interval: number= 1
update frequency (defaults to 1 second)
Returns: object
- remove(): void
onMediaStatusUpdated
▸ onMediaStatusUpdated(handler
: function): EmitterSubscription
Called when media status changes.
Parameters:
▪ handler: function
▸ (mediaStatus
: MediaStatus | null): void
Parameters:
Name | Type |
---|---|
mediaStatus | MediaStatus | null |
Returns: EmitterSubscription
pause
▸ pause(customData?
: undefined | object): Promise‹void›
Pauses playback of the current media item.
The request will fail if there is no current media status.
Parameters:
Name | Type | Description |
---|---|---|
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
play
▸ play(customData?
: undefined | object): Promise‹void›
Begins (or resumes) playback of the current media item.
Playback always begins at the beginning of the stream. The request will fail if there is no current media status.
Parameters:
Name | Type | Description |
---|---|---|
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
queueInsertAndPlayItem
▸ queueInsertAndPlayItem(item
: MediaQueueItem, beforeItemId?
: undefined | number, playPosition?
: undefined | number, customData?
: undefined | object): Promise‹void›
Inserts a single item into the queue and starts playing it at the specified position.
Parameters:
Name | Type | Description |
---|---|---|
item | MediaQueueItem | The item to insert. |
beforeItemId? | undefined | number | The ID of the item that will be located immediately after the inserted item. If the value is null , or does not refer to any item currently in the queue, the inserted item will be appended to the end of the queue. |
playPosition? | undefined | number | The initial playback position for the item when it is first played, relative to the beginning of the stream. This value is ignored when the same item is played again, for example when the queue repeats, or the item is later jumped to. In those cases the item's startTime is used. |
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
queueInsertItem
▸ queueInsertItem(item
: MediaQueueItem, beforeItemId?
: number | null, customData?
: undefined | object): Promise‹void›
Inserts a single item into the queue.
Parameters:
Name | Type | Description |
---|---|---|
item | MediaQueueItem | The item to insert. |
beforeItemId? | number | null | The ID of the item that will be located immediately after the inserted item. If the value is null , or does not refer to any item currently in the queue, the inserted item will be appended to the end of the queue. |
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
queueInsertItems
▸ queueInsertItems(items
: MediaQueueItem[], beforeItemId?
: number | null, customData?
: undefined | object): Promise‹void›
Inserts a list of new media items into the queue.
Parameters:
Name | Type | Description |
---|---|---|
items | MediaQueueItem[] | List of items to insert into the queue, in the order that they should be played. The itemId field of the items should be unassigned. |
beforeItemId? | number | null | The ID of the item that will be located immediately after the inserted list. If the value is null , or does not refer to any item currently in the queue, the inserted list will be appended to the end of the queue. |
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
queueNext
▸ queueNext(customData?
: undefined | object): Promise‹void›
Moves to the next item in the queue.
Parameters:
Name | Type | Description |
---|---|---|
customData? | undefined | object | Custom application-specific data to pass along with the request. (Currently Android only. On iOS customData will be ignored.) |
Returns: Promise‹void›
queuePrev
▸ queuePrev(customData?
: undefined | object): Promise‹void›
Moves to the previous item in the queue.
Parameters:
Name | Type | Description |
---|---|---|
customData? | undefined | object | Custom application-specific data to pass along with the request. (Currently Android only. On iOS customData will be ignored.) |
Returns: Promise‹void›
requestStatus
▸ requestStatus(): Promise‹void›
Requests updated media status information from the receiver. This method returns void but the result will trigger the onMediaStatusUpdated
event and update useMediaStatus
.
Returns: Promise‹void›
seek
▸ seek(options
: MediaSeekOptions): Promise‹void›
Seeks to a new position within the current media item.
Parameters:
Name | Type |
---|---|
options | MediaSeekOptions |
Returns: Promise‹void›
setActiveMediaTracks
▸ setActiveMediaTracks(trackIds
: number[]): Promise‹void›
deprecated
Use setActiveTrackIds
instead.
Parameters:
Name | Type | Default |
---|---|---|
trackIds | number[] | [] |
Returns: Promise‹void›
setActiveTrackIds
▸ setActiveTrackIds(trackIds
: number[]): Promise‹void›
Sets the active media tracks.
The request will fail if there is no current media status.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
trackIds | number[] | [] | The media track IDs. If undefined or an empty array, the current set of active trackIds will be removed, and default ones will be used instead. |
Returns: Promise‹void›
setPlaybackRate
▸ setPlaybackRate(playbackRate
: number, customData?
: undefined | object): Promise‹void›
Sets the playback rate for the current media session.
Parameters:
Name | Type | Description |
---|---|---|
playbackRate | number | The new playback rate, between 0.5 and 2.0 . The normal rate is 1.0 . |
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
setStreamMuted
▸ setStreamMuted(muted
: boolean, customData?
: undefined | object): Promise‹void›
Sets whether the stream is muted.
The request will fail if there is no current media session.
Parameters:
Name | Type | Description |
---|---|---|
muted | boolean | Whether the stream should be muted or unmuted. |
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
setStreamVolume
▸ setStreamVolume(volume
: number, customData?
: undefined | object): Promise‹void›
Sets the stream volume.
Parameters:
Name | Type | Description |
---|---|---|
volume | number | The new volume, between 0.0 and 1.0 . |
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›
setTextTrackStyle
▸ setTextTrackStyle(textTrackStyle
: TextTrackStyle): Promise‹void›
Sets the text track style.
The request will fail if there is no current media status.
Parameters:
Name | Type | Description |
---|---|---|
textTrackStyle | TextTrackStyle | The text track style. |
Returns: Promise‹void›
stop
▸ stop(customData?
: undefined | object): Promise‹void›
Stops playback of the current media item.
If a queue is currently loaded, it will be removed. The request will fail if there is no current media status.
Parameters:
Name | Type | Description |
---|---|---|
customData? | undefined | object | Custom application-specific data to pass along with the request. |
Returns: Promise‹void›