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

CastSession

Cast sessions are created and managed automatically by the SessionManager, for example when the user selects a Cast device from the media route controller dialog. The current active CastSession can be accessed by {@link CastContext.getCurrentCastSession}.

see Android | iOS | Chrome

example

import { useCastSession } from 'react-native-google-cast'

function MyComponent() {
  const castSession = useCastSession()

  if (castSession) {
    // ...
  }
}

Hierarchy

  • CastSession

Index

Constructors

  • constructor

Properties

  • client
  • id

Methods

  • addChannel
  • getActiveInputState
  • getApplicationMetadata
  • getApplicationStatus
  • getCastDevice
  • getClient
  • getStandbyState
  • getVolume
  • isMute
  • onActiveInputStateChanged
  • onStandbyStateChanged
  • setMute
  • setVolume

Constructors

constructor

+ new CastSession(args: object): CastSession

Parameters:

▪ args: object

NameType
id?undefined | string

Returns: CastSession

Properties

client

• client: RemoteMediaClient‹› = new RemoteMediaClient()


Optional id

• id? : undefined | string

Unique session ID.

Methods

addChannel

▸ addChannel(namespace: string): Promise‹CastChannel›

Creates a channel for sending custom messages between this sender and the Cast receiver. Use when you've built a custom receiver and want to communicate with it.

Parameters:

NameTypeDescription
namespacestringA custom channel identifier starting with urn:x-cast:, for example urn:x-cast:com.reactnative.googlecast.example. The namespace name is arbitrary; just make sure it's unique.

Returns: Promise‹CastChannel›


getActiveInputState

▸ getActiveInputState(): Promise‹ActiveInputState›

Indicates whether a receiver device is currently the active video input. Active input state can only be reported when the Google cast device is connected to a TV or AVR with CEC support.

Returns: Promise‹ActiveInputState›


getApplicationMetadata

▸ getApplicationMetadata(): Promise‹ApplicationMetadata›

Returns the metadata for the currently running receiver application, or null if the metadata is unavailable.

see Android | iOS | Chrome

Returns: Promise‹ApplicationMetadata›


getApplicationStatus

▸ getApplicationStatus(): Promise‹string›

Returns the current receiver application status, if any. Message text is localized to the Google Cast device's locale.

see Android | iOS deviceStatusText | Chrome

Returns: Promise‹string›


getCastDevice

▸ getCastDevice(): Promise‹Device | null›

see Android | iOS | Chrome

Returns: Promise‹Device | null›


getClient

▸ getClient(): RemoteMediaClient

Returns: RemoteMediaClient


getStandbyState

▸ getStandbyState(): Promise‹StandbyState›

Indicates whether a receiver device's connected TV or AVR is currently in "standby" mode.

Returns: Promise‹StandbyState›


getVolume

▸ getVolume(): Promise‹number›

Returns the device's volume.

see Android | iOS

Returns: Promise‹number›

Volume in the range [0.0, 1.0].


isMute

▸ isMute(): Promise‹boolean›

see Android

Returns: Promise‹boolean›


onActiveInputStateChanged

▸ onActiveInputStateChanged(listener: function): EmitterSubscription

Listen for changes to the active input state.

example

const subscription = session.onActiveInputStateChanged(state => { ... })

// later, to stop listening
subscription.remove()

Parameters:

▪ listener: function

▸ (state: ActiveInputState): void

Parameters:

NameType
stateActiveInputState

Returns: EmitterSubscription


onStandbyStateChanged

▸ onStandbyStateChanged(listener: function): EmitterSubscription

Listen for changes to the standby state.

example

const subscription = session.onStandbyStateChanged(state => { ... })

// later, to stop listening
subscription.remove()

Parameters:

▪ listener: function

▸ (state: StandbyState): void

Parameters:

NameType
stateStandbyState

Returns: EmitterSubscription


setMute

▸ setMute(mute: boolean): void

Mutes or unmutes the device's audio.

Note that this method doesn't currently resolve a promise. You may instead call client.setStreamMuted() which handles promises correctly.

see Android | iOS

Parameters:

NameTypeDescription
mutebooleanThe new mute state.

Returns: void


setVolume

▸ setVolume(volume: number): void

Sets the device volume.

Note that this method doesn't currently resolve a promise. You may instead call client.setStreamVolume() which handles promises correctly.

see Android | iOS

Parameters:

NameTypeDescription
volumenumberIf volume is outside of the range [0.0, 1.0], then the value will be clipped.

Returns: void

← CastContextDiscoveryManager →
  • Hierarchy
  • Index
    • Constructors
    • Properties
    • Methods
  • Constructors
    • constructor
  • Properties
    • client
    • Optional id
  • Methods
    • addChannel
    • getActiveInputState
    • getApplicationMetadata
    • getApplicationStatus
    • getCastDevice
    • getClient
    • getStandbyState
    • getVolume
    • isMute
    • onActiveInputStateChanged
    • onStandbyStateChanged
    • setMute
    • setVolume