React Native Google Cast

React Native Google Cast

  • Docs
  • GitHub

›API

Getting Started

  • Installation
  • Setup
  • Usage
  • Troubleshooting

Guides

  • Custom Channels
  • Customize UI
  • Events
  • Hooks
  • Media Tracks
  • Queueing
  • Volume

Components

  • CastButton
  • ExpandedController

API

  • CastChannel
  • CastContext
  • CastSession
  • DiscoveryManager
  • RemoteMediaClient
  • SessionManager

Types

  • ApplicationMetadata
  • Device
  • MediaInfo
  • MediaLiveSeekableRange
  • MediaLoadRequest
  • MediaMetadata
    • Generic
    • Movie
    • MusicTrack
    • Photo
    • TvShow
    • User
  • MediaQueueContainerMetadata
  • MediaQueueData
  • MediaQueueItem
  • MediaSeekOptions
  • MediaStatus
  • MediaTrack
  • TextTrackStyle
  • UseCastSessionOptions
  • VideoInfo
  • WebImage

Enums

  • ActiveInputState
  • CastState
  • MediaHlsSegmentFormat
  • MediaHlsVideoSegmentFormat
  • MediaPlayerIdleReason
  • MediaPlayerState
  • MediaQueueContainerType
  • MediaQueueType
  • MediaRepeatMode
  • MediaStreamType
  • PlayServicesState
  • StandbyState

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

  • progressUpdateListener

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:

NameType
requestMediaLoadRequest

Returns: Promise‹void›


onMediaPlaybackEnded

▸ onMediaPlaybackEnded(handler: function): EmitterSubscription

Called when finished playback of an item.

Parameters:

▪ handler: function

▸ (mediaStatus: MediaStatus | null): void

Parameters:

NameType
mediaStatusMediaStatus | null

Returns: EmitterSubscription


onMediaPlaybackStarted

▸ onMediaPlaybackStarted(handler: function): EmitterSubscription

Called when started playback of an item.

Parameters:

▪ handler: function

▸ (mediaStatus: MediaStatus | null): void

Parameters:

NameType
mediaStatusMediaStatus | 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:

NameType
progressnumber
durationnumber

▪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:

NameType
mediaStatusMediaStatus | 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:

NameTypeDescription
customData?undefined | objectCustom 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:

NameTypeDescription
customData?undefined | objectCustom 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:

NameTypeDescription
itemMediaQueueItemThe item to insert.
beforeItemId?undefined | numberThe 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 | numberThe 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 | objectCustom 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:

NameTypeDescription
itemMediaQueueItemThe item to insert.
beforeItemId?number | nullThe 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 | objectCustom 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:

NameTypeDescription
itemsMediaQueueItem[]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 | nullThe 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 | objectCustom 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:

NameTypeDescription
customData?undefined | objectCustom 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:

NameTypeDescription
customData?undefined | objectCustom 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:

NameType
optionsMediaSeekOptions

Returns: Promise‹void›


setActiveMediaTracks

▸ setActiveMediaTracks(trackIds: number[]): Promise‹void›

deprecated Use setActiveTrackIds instead.

Parameters:

NameTypeDefault
trackIdsnumber[][]

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:

NameTypeDefaultDescription
trackIdsnumber[][]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:

NameTypeDescription
playbackRatenumberThe new playback rate, between 0.5 and 2.0. The normal rate is 1.0.
customData?undefined | objectCustom 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:

NameTypeDescription
mutedbooleanWhether the stream should be muted or unmuted.
customData?undefined | objectCustom 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:

NameTypeDescription
volumenumberThe new volume, between 0.0 and 1.0.
customData?undefined | objectCustom 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:

NameTypeDescription
textTrackStyleTextTrackStyleThe 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:

NameTypeDescription
customData?undefined | objectCustom application-specific data to pass along with the request.

Returns: Promise‹void›

← DiscoveryManagerSessionManager →
  • Hierarchy
  • Index
    • Properties
    • Methods
  • Properties
    • Private Optional progressUpdateListener
  • Methods
    • getMediaStatus
    • getStreamPosition
    • loadMedia
    • onMediaPlaybackEnded
    • onMediaPlaybackStarted
    • onMediaProgressUpdated
    • onMediaStatusUpdated
    • pause
    • play
    • queueInsertAndPlayItem
    • queueInsertItem
    • queueInsertItems
    • queueNext
    • queuePrev
    • requestStatus
    • seek
    • setActiveMediaTracks
    • setActiveTrackIds
    • setPlaybackRate
    • setStreamMuted
    • setStreamVolume
    • setTextTrackStyle
    • stop