chromecast-js
chromecast-js is a javascript client library for googlecast's remote playback protocol that uses DefaultMediaReceiver to play any (compatible) content in the Chromecast, it works by wrapping the node-castv2-client module.
Installation
From npm:
npm install chromecast-js
Usage
chromecastjs = require ( ' chromecast-js ' )
var browser = new chromecastjs . Browser ( )
browser . on ( ' deviceOn ' , function ( device ) {
device . connect ( )
device . on ( ' connected ' , function ( ) {
device . play ( ' http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4 ' , 60 , function ( ) {
console . log ( ' Playing in your chromecast! ' )
} ) ;
setTimeout ( function ( ) {
device . pause ( function ( ) {
console . log ( ' Paused! ' )
} ) ;
} , 30000 ) ;
setTimeout ( function ( ) {
device . stop ( function ( ) {
console . log ( ' Stoped! ' )
} ) ;
} , 40000 ) ;
} )
} )
Subtitles and Cover
To include subtitles and a cover image with the media title, use an Object instead of a string in the play method :
chromecastjs = require ( ' ../ ' )
var browser = new chromecastjs . Browser ( )
var media = {
url : ' http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4 ' ,
subtitles : [ {
language : ' en-US ' ,
url : ' http://carlosguerrero.com/captions_styled.vtt ' ,
name : ' English ' ,
} ,
{
language : ' es-ES ' ,
url : ' http://carlosguerrero.com/captions_styled_es.vtt ' ,
name : ' Spanish ' ,
}
] ,
cover : {
title : ' Big Bug Bunny ' ,
url : ' http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg '
} ,
subtitles_style : {
backgroundColor : ' #FFFFFFFF ' ,
foregroundColor : ' #000FFFF ' ,
edgeType : ' DROP_SHADOW ' ,
edgeColor : ' #AA00FFFF ' ,
fontScale : 1 . 5 ,
fontStyle : ' BOLD_ITALIC ' ,
fontFamily : ' Droid Sans ' ,
fontGenericFamily : ' CURSIVE ' ,
windowColor : ' #AA00FFFF ' ,
windowRoundedCornerRadius : 10 ,
windowType : ' ROUNDED_CORNERS '
}
}
browser . on ( ' deviceOn ' , function ( device ) {
device . connect ( )
device . on ( ' connected ' , function ( ) {
device . play ( media , 0 , function ( ) {
console . log ( ' Playing in your chromecast! ' )
setTimeout ( function ( ) {
console . log ( ' subtitles off! ' )
device . subtitlesOff ( function ( err , status ) {
if ( err ) console . log ( " error setting subtitles off... " )
console . log ( " subtitles removed. " )
} ) ;
} , 20000 ) ;
setTimeout ( function ( ) {
console . log ( ' subtitles on! ' )
device . changeSubtitles ( 1 , function ( err , status ) {
if ( err ) console . log ( " error restoring subtitles... " )
console . log ( " subtitles restored. " )
} ) ;
} , 25000 ) ;
setTimeout ( function ( ) {
console . log ( ' subtitles on! ' )
device . changeSubtitles ( 1 , function ( err , status ) {
if ( err ) console . log ( " error restoring subtitles... " )
console . log ( " subtitles restored. " )
} ) ;
} , 25000 ) ;
setTimeout ( function ( ) {
device . pause ( function ( ) {
console . log ( ' Paused! ' )
} ) ;
} , 30000 ) ;
setTimeout ( function ( ) {
device . unpause ( function ( ) {
console . log ( ' unpaused! ' )
} ) ;
} , 40000 ) ;
setTimeout ( function ( ) {
console . log ( ' I ment English subtitles! ' )
device . changeSubtitles ( 0 , function ( err , status ) {
if ( err ) console . log ( " error restoring subtitles... " )
console . log ( " English subtitles restored. " )
} ) ;
} , 45000 ) ;
setTimeout ( function ( ) {
console . log ( ' Increasing subtitles size... ' )
device . changeSubtitlesSize ( 10 , function ( err , status ) {
if ( err ) console . log ( " error increasing subtitles size... " )
console . log ( " subtitles size increased. " )
} ) ;
} , 46000 ) ;
setTimeout ( function ( ) {
device . seek ( 30 , function ( ) {
console . log ( ' seeking forward! ' )
} ) ;
} , 50000 ) ;
setTimeout ( function ( ) {
console . log ( ' decreasing subtitles size... ' )
device . changeSubtitlesSize ( 1 , function ( err , status ) {
if ( err ) console . log ( " error... " )
console . log ( " subtitles size decreased. " )
} ) ;
} , 60000 ) ;
setTimeout ( function ( ) {
device . pause ( function ( ) {
console . log ( ' Paused! ' )
} ) ;
} , 70000 ) ;
setTimeout ( function ( ) {
device . seek ( 30 , function ( ) {
console . log ( ' seeking forward! ' )
} ) ;
} , 80000 ) ;
setTimeout ( function ( ) {
device . seek ( 30 , function ( ) {
console . log ( ' seeking forward! ' )
} ) ;
} , 85000 ) ;
setTimeout ( function ( ) {
device . unpause ( function ( ) {
console . log ( ' unpaused! ' )
} ) ;
} , 90000 ) ;
setTimeout ( function ( ) {
device . seek ( - 30 , function ( ) {
console . log ( ' seeking backwards! ' )
} ) ;
} , 100000 ) ;
setTimeout ( function ( ) {
device . stop ( function ( ) {
console . log ( ' Stoped! ' )
} ) ;
} , 200000 ) ;
} )
} )
}