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
npm install @capnative/capacitor-chromecast
npx cap syncUsage
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.INTERNETandroid.permission.ACCESS_NETWORK_STATEandroid.permission.ACCESS_WIFI_STATEandroid.permission.CHANGE_WIFI_STATEandroid.hardware.wifiwithandroid: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.
initialize(options: InitializeOptions) => Promise<void>| Param | Type | Description |
|---|---|---|
| options | InitializeOptions | Receiver application ID from the Google Cast Developer Console. |
show()
Opens the official native Google Cast device picker.
show() => Promise<void>loadMedia()
Loads media from a URL on the currently connected Chromecast device.
loadMedia(options: LoadMediaOptions) => Promise<void>| Param | Type | Description |
|---|---|---|
| options | LoadMediaOptions | Absolute 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.
isConnected() => Promise<boolean>Returns Promise<boolean>
removeAllListeners()
Removes listeners registered on this plugin.
removeAllListeners() => Promise<void>Events
sessionStateChanged
Fires when the Cast session state changes.
addListener('sessionStateChanged', listenerFunc: (event: SessionStateChangedEvent) => void) => Promise<PluginListenerHandle>Payload: SessionStateChangedEvent — `state` is 'connecting', 'connected', or 'disconnected'.
Interfaces
InitializeOptions
| Property | Type | Description |
|---|---|---|
| receiverApplicationId | string | Google Cast receiver application ID. Must be 8 hexadecimal characters, such as CC1AD845 in the plugin's own comment. |
LoadMediaOptions
| Property | Type | Description |
|---|---|---|
| url | string | Absolute URL of the media to load on the connected Chromecast device. |
SessionStateChangedEvent
| Property | Type | Description |
|---|---|---|
| state | SessionState |
PluginListenerHandle
| Property | Type | Description |
|---|---|---|
| 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.
| Code | Platform | Meaning |
|---|---|---|
| INVALID_RECEIVER_APPLICATION_ID | iOS, Android, Web | The 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_PLATFORM | Web | Web calls reject with "Chromecast is not supported on the web platform." initialize still validates the receiver ID first. |
| NOT_INITIALIZED | TODO | TODO: declared in src/errors.ts. The README does not say which call raises it. |
| INVALID_MEDIA_URL | TODO | TODO: declared in src/errors.ts. The README does not say which call raises it. |
| CAST_NOT_AVAILABLE | TODO | TODO: declared in src/errors.ts. The README does not say which call raises it. |
| CAST_CONNECTION_FAILED | TODO | TODO: declared in src/errors.ts. The README does not say which call raises it. |
| CAST_SESSION_NOT_CONNECTED | TODO | TODO: declared in src/errors.ts. The README does not say which call raises it. |
| MEDIA_LOAD_FAILED | TODO | TODO: declared in src/errors.ts. The README does not say which call raises it. |