- Notifications
You must be signed in to change notification settings - Fork49
📺 Chromecast Node.js module
License
alxhotel/chromecast-api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
chromecast-api is a NodeJS module to play any content in your Chromecast device.
npm install chromecast-api
constChromecastAPI=require('chromecast-api')constclient=newChromecastAPI()client.on('device',function(device){varmediaURL='http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4';device.play(mediaURL,function(err){if(!err)console.log('Playing in your chromecast')})})
- Media (video and audio)
- Youtube videos
To include subtitles and a cover image, use an Object instead of a string in the functionplay(mediaObject)
:
Note: your subtitles must implement CORS.
constChromecastAPI=require('chromecast-api')constmedia={url :'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4',subtitles:[{language:'en-US',url:'https://raw.githubusercontent.com/alxhotel/chromecast-api/master/test/captions_styled.vtt',name:'English',},{language:'es-ES',url:'https://raw.githubusercontent.com/alxhotel/chromecast-api/master/test/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:'#FFFFFF00',// see http://dev.w3.org/csswg/css-color/#hex-notationforegroundColor:'#FFFFFFFF',// see http://dev.w3.org/csswg/css-color/#hex-notationedgeType:'OUTLINE',// can be: "NONE", "OUTLINE", "DROP_SHADOW", "RAISED", "DEPRESSED"edgeColor:'#000000FF',// see http://dev.w3.org/csswg/css-color/#hex-notationfontScale:1.2,// transforms into "font-size: " + (fontScale*100) +"%"fontStyle:'BOLD',// can be: "NORMAL", "BOLD", "BOLD_ITALIC", "ITALIC",fontFamily:'Droid Sans',fontGenericFamily:'SANS_SERIF',// can be: "SANS_SERIF", "MONOSPACED_SANS_SERIF", "SERIF", "MONOSPACED_SERIF", "CASUAL", "CURSIVE", "SMALL_CAPITALS",//windowColor: '#AA00FFFF', // see http://dev.w3.org/csswg/css-color/#hex-notation//windowRoundedCornerRadius: 10, // radius in px//windowType: 'ROUNDED_CORNERS' // can be: "NONE", "NORMAL", "ROUNDED_CORNERS"}}constclient=newChromecastAPI()client.on('device',function(device){device.play(media,function(err){if(!err)console.log('Playing in your chromecast')})})
Initialize the client to start searching for chromecast devices.
Listen for new devices by passingcallback(device)
in the callback parameter.
With theDevice
object you can now interact with your Chromecast.
This is an example of the attributes ofdevice
:
{ name: 'Chromecast-e363e7-3e23e2e-3e2e-23e34e._googlecast._tcp.local', // Unique identifier friendlyName: 'Bobby', // The name you gave to your chromecast host: '192.168.1.10' // Local IP address}
An array of all devices found by the client.
Trigger the mDNS and SSDP search again. Warning: thedevice
event will trigger again (it might return the same device).
Use this function to play any media in the chromecast device. Make suremediaURL
is accessible by the chromecast.
Pass an attributestartTime
in theopts
object to set where to start an audio or video content (in seconds).
{ startTime: 120 // Start the content at the 2 minute mark}
Pause the media.
Resume the media.
Stop playing the media.
Seek forwardseconds
in time.
Seek to thespecificTime
in seconds.
Set the volume to a specificlevel
(from 0.0 to 1.0).
Change the subtitles by passing the index of the subtitle you want based on the list you passed before.
Choose the subtitles font size withfontSize
. The default is1.0
.
Turn the subtitles off.
Get the current time of the media playing (in seconds). It's a shortcut for getting thecurrentTime
from the status.
Close the connection with the device.
Event emitted when the client is connected to the device.
Event emitted when the media (audio or video) has finished.
Event emitted when the device has a new status:callback(status)
.
- Supported Media:https://developers.google.com/cast/docs/media
- Receiver Apps:https://developers.google.com/cast/docs/receiver_apps
MIT. Copyright (c)Alex
About
📺 Chromecast Node.js module