https://github.com/francescocioria/chromecast-media-controls-api
API to control any media running on the Chromecast
https://github.com/francescocioria/chromecast-media-controls-api
cast chromecast chromecast-api media media-controller
Last synced: about 8 hours ago
JSON representation
API to control any media running on the Chromecast
- Host: GitHub
- URL: https://github.com/francescocioria/chromecast-media-controls-api
- Owner: FrancescoCioria
- Created: 2021-03-19T14:24:53.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-29T12:20:33.000Z (about 5 years ago)
- Last Synced: 2025-02-05T06:47:04.808Z (over 1 year ago)
- Topics: cast, chromecast, chromecast-api, media, media-controller
- Language: TypeScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# chromecast-media-controls
API to control any media running on the Chromecast
## Install
```
yarn add chromecast-media-controls
```
## Usage
```ts
import {
ChromecastMediaControls,
// useful to check in advance if we can call media actions like pause() or resume()
appSupportsMediaControls
} from "chromecast-media-controls";
const chromecast = new ChromecastMediaControls({
// called whenever the client receives an error message
onError: (error: Error) => {
// handle error
},
/*
called if the connection to the device is lost
NOTE: this is not called after manually invoking "chromecast.closeConnection()"
*/
onDisconnect: () => {
// handle disconnection, usually by re-initializing:
chromecast.initialize();
}
});
/*
initialize connection:
- find Chromecast device on network
- establish connection to Chromecast device
- initilize listeners (onError, onDisconnect)
- look for active media session, if any
*/
await chromecast.initialize();
// pause
await chromecast.pause();
// resume
await chromecast.resume();
// stop
await chromecast.stop(); // closes current application
// seek
await chromecast.seek(120); // 120 seconds from beginning of media
// change volume
await chromecast.setVolume({ level: 0.2, muted: false });
// get current volume
const currentVolume = await chromecast.getVolume();
// returns "true" if client has been initialized and we are connected to a Chromecast device
chromecast.isConnected();
// get current media session
const currentMediaSession = await chromecast.getStatus();
// get current client session
const currentClientSession = await chromecast.session();
// close connection (you'll have to re-initialize after this)
await chromecast.closeConnection();
// low level usage
const player = await chromecast.player();
player._player; // -> instance of DefaultMediaReceiver from "castv2-client" library
chromcast.client._client; // -> instance of Platform sender from "castv2-client" library
```