Skip to content

Instantly share code, notes, and snippets.

@tuliofaria
Created December 22, 2017 23:09
Show Gist options
  • Save tuliofaria/337ea7cf83b5125ff78fe0bc9bee8eb5 to your computer and use it in GitHub Desktop.
Save tuliofaria/337ea7cf83b5125ff78fe0bc9bee8eb5 to your computer and use it in GitHub Desktop.
Playing a video in Chromecast with NodeJS
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()
{
"dependencies": {
"castv2-client": "^1.2.0",
"mdns": "^2.3.4"
}
}
Copy link

ghost commented May 15, 2021

hello friend, can i get a link of sound of nature? tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment