Created
December 22, 2017 23:09
-
-
Save tuliofaria/337ea7cf83b5125ff78fe0bc9bee8eb5 to your computer and use it in GitHub Desktop.
Playing a video in Chromecast with NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mdns = require('mdns') | |
const Client = require('castv2-client').Client | |
const DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver | |
const playMedia = host => { | |
const client = new Client() | |
client.connect(host, () => { | |
console.log('connected') | |
client.launch(DefaultMediaReceiver, (err, player) => { | |
const media = { | |
contentId: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4', | |
contentType: 'video/mp4', | |
streamType: 'BUFFERED', | |
metadata:{ | |
type: 0, | |
metadataType: 0, | |
title: 'Coelinho', | |
images:[ | |
{ url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg'} | |
] | |
} | |
} | |
player.on('status', status => { | |
console.log('status', status.playerState) | |
}) | |
player.load(media, { autoplay: true }, (err, status) => { | |
console.log('playing', status.playerState) | |
setTimeout(() => { | |
player.seek(2*60, (err, status) => { | |
}) | |
}, 10000) | |
}) | |
}) | |
}) | |
} | |
const browser = mdns.createBrowser(mdns.tcp('googlecast')) | |
browser.on('serviceUp', service => { | |
const { md, fn } = service.txtRecord | |
console.log(md, fn) | |
playMedia(service.addresses[0]) | |
}) | |
browser.on('serviceDown', service => { | |
const { md, fn } = service.txtRecord | |
console.log(md, fn) | |
}) | |
/*setTimeout(() => { | |
browser.stop() | |
}, 5000)*/ | |
browser.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"castv2-client": "^1.2.0", | |
"mdns": "^2.3.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello friend, can i get a link of sound of nature? tks