Skip to content
CapNative

Chromecast

Open the Google Cast device picker and load media from a Capacitor app.

  • iOS, supported
  • Android, supported
  • Web, not supported
Package
@capnative/capacitor-chromecast
npm version
8.2.1
Capacitor
8.x · MIT

API checked against the repository README, TypeScript definitions, and npm on October 25, 2026.The README marks this major as maintained.

Install

Peer dependency: @capacitor/core >= 8.0.0

bash
npm install @capnative/capacitor-chromecast
npx cap sync

Usage

typescript
import { Chromecast } from '@capnative/capacitor-chromecast';

await Chromecast.initialize({
  receiverApplicationId: 'YOUR_RECEIVER_APPLICATION_ID',
});

await Chromecast.addListener('sessionStateChanged', async (event) => {
  if (event.state === 'connected') {
    await Chromecast.loadMedia({
      url: 'https://example.com/video.mp4',
    });
  }
});

await Chromecast.show();

Platform setup

Chromecast runs on the native iOS and Android implementations. Web calls reject with UNSUPPORTED_PLATFORM.

You must provide a Google Cast receiver application ID, either to initialize or in Capacitor config. The package trims and uppercases the ID, then requires it to match ^[A-F0-9]{8}$. The shape cited in the plugin source is CC1AD845. Replace YOUR_RECEIVER_APPLICATION_ID with the ID from the Google Cast Developer Console.

Capacitor config

capacitor.config.ts, as published in the plugin README:

import { CapacitorConfig } from '@capacitor/cli';

export default CapacitorConfig({
  plugins: {
    Chromecast: {
      receiverApplicationId: 'YOUR_RECEIVER_APPLICATION_ID',
    },
  },
});

capacitor.config.json:

{
  "plugins": {
    "Chromecast": {
      "receiverApplicationId": "YOUR_RECEIVER_APPLICATION_ID"
    }
  }
}

iOS

Google Cast discovery needs local-network and Bonjour entries in the app Info.plist:

<key>NSLocalNetworkUsageDescription</key>
<string>This app uses Google Cast to discover and connect to nearby devices.</string>
<key>NSBonjourServices</key>
<array>
  <string>_googlecast._tcp</string>
  <string>_YOUR_RECEIVER_APPLICATION_ID._googlecast._tcp</string>
</array>

Minimum version is iOS 15. The README says a Bluetooth-enabled Google Cast SDK may also need Bluetooth usage descriptions, and points at Google’s Cast iOS setup for the SDK distribution you use. This repository does not list those keys.

Android

Minimum version is API 24. The plugin manifest is merged into the app and already declares:

  • android.permission.INTERNET
  • android.permission.ACCESS_NETWORK_STATE
  • android.permission.ACCESS_WIFI_STATE
  • android.permission.CHANGE_WIFI_STATE
  • android.hardware.wifi with android:required="true"

It also registers the Cast options provider com.marioshtika.capacitorchromecast.ChromecastOptionsProvider and androidx.mediarouter.media.MediaTransferReceiver. Do not copy those entries into the app manifest.

The Android library depends on com.google.android.gms:play-services-cast-framework. The default version in the plugin Gradle file is 21.4.0 unless the app sets playServicesCastFrameworkVersion.

android:required="true" on Wi-Fi is part of the merged manifest, so the app will require Wi-Fi hardware.

Not implemented

The README lists follow-up APIs that are not in this version: getSession, disconnect, play, pause, stop, seek, setVolume, and getMediaStatus.

API

Method signatures match Chromecast in the plugin repository. Import it from @capnative/capacitor-chromecast.

initialize()

Initializes the native Google Cast SDK with your receiver application ID. Call this once during startup, or set the same value in capacitor config under plugins.Chromecast.receiverApplicationId.

Signature
initialize(options: InitializeOptions) => Promise<void>
ParamTypeDescription
optionsInitializeOptionsReceiver application ID from the Google Cast Developer Console.

show()

Opens the official native Google Cast device picker.

Signature
show() => Promise<void>

loadMedia()

Loads media from a URL on the currently connected Chromecast device.

Signature
loadMedia(options: LoadMediaOptions) => Promise<void>
ParamTypeDescription
optionsLoadMediaOptionsAbsolute URL of the media to load.

isConnected()

Returns whether there is an active Chromecast device connection. The JavaScript client unwraps the native result `{ isConnected: boolean }` and returns the boolean.

Signature
isConnected() => Promise<boolean>

Returns Promise<boolean>

removeAllListeners()

Removes listeners registered on this plugin.

Signature
removeAllListeners() => Promise<void>

Events

sessionStateChanged

Fires when the Cast session state changes.

Signature
addListener('sessionStateChanged', listenerFunc: (event: SessionStateChangedEvent) => void) => Promise<PluginListenerHandle>

Payload: SessionStateChangedEvent — `state` is 'connecting', 'connected', or 'disconnected'.

Interfaces

InitializeOptions

PropertyTypeDescription
receiverApplicationIdstringGoogle Cast receiver application ID. Must be 8 hexadecimal characters, such as CC1AD845 in the plugin's own comment.

LoadMediaOptions

PropertyTypeDescription
urlstringAbsolute URL of the media to load on the connected Chromecast device.

SessionStateChangedEvent

PropertyTypeDescription
stateSessionState

PluginListenerHandle

PropertyTypeDescription
remove() => Promise<void>Removes this listener.

Type aliases

  • SessionState

    'connecting' | 'connected' | 'disconnected'

  • ChromecastErrorCode

    'NOT_INITIALIZED' | 'INVALID_RECEIVER_APPLICATION_ID' | 'INVALID_MEDIA_URL' | 'CAST_NOT_AVAILABLE' | 'CAST_CONNECTION_FAILED' | 'CAST_SESSION_NOT_CONNECTED' | 'MEDIA_LOAD_FAILED' | 'UNSUPPORTED_PLATFORM'

    Declared in src/errors.ts and attached to rejected errors as error.code.

Errors

Rejected promises expose a stable code. Match on that code rather than the message text.

CodePlatformMeaning
INVALID_RECEIVER_APPLICATION_IDiOS, Android, WebThe receiver application ID is missing or is not 8 hexadecimal characters after trim and uppercase. Message from the package is "Receiver application ID must be an 8-character hexadecimal Google Cast receiver application ID."
UNSUPPORTED_PLATFORMWebWeb calls reject with "Chromecast is not supported on the web platform." initialize still validates the receiver ID first.
NOT_INITIALIZEDTODOTODO: declared in src/errors.ts. The README does not say which call raises it.
INVALID_MEDIA_URLTODOTODO: declared in src/errors.ts. The README does not say which call raises it.
CAST_NOT_AVAILABLETODOTODO: declared in src/errors.ts. The README does not say which call raises it.
CAST_CONNECTION_FAILEDTODOTODO: declared in src/errors.ts. The README does not say which call raises it.
CAST_SESSION_NOT_CONNECTEDTODOTODO: declared in src/errors.ts. The README does not say which call raises it.
MEDIA_LOAD_FAILEDTODOTODO: declared in src/errors.ts. The README does not say which call raises it.