thibauts / node-castv2-client

A Chromecast client based on the new (CASTV2) protocol
MIT License
646 stars 92 forks source link

How to get information about played movie/song #74

Open pouniok opened 6 years ago

pouniok commented 6 years ago

Hello,

Is there a way to get a status update when something is streamed on the Chromecast, like the Title, duration, current position in the movie and a snapshot or background picture ?

I can't find any clue on how to do that, everything seems oriented on sending information to the chromecast :)

Thanks !

pedromsilvapt commented 6 years ago

Have you tried the player.getStatus() method? Note that this method works only when using the DefaultMediaReceiver, and afaik, you need to at least know what app is receiving to use it.

NOTE I'm using the async/await syntax for clarity, but if you want I can write it using callbacks either way.

// Small helper function to use promises and async/await instead of callbacks
const co = ( c : any, b : string ) => util.promisify( c[ b ].bind( c ) );

let client = new Client();

await co( client, 'connect' )( CHROMECAST_IP_ADDRESS );

const apps = await co( client, 'getStatus' )();

const sessionId : string = apps.applications[ 0 ];

const player = await co( client, 'join' )( sessionId, DefaultMediaReceiver );

const status = await co( player, 'getStatus' )();

console.log( status );