Socket
Socket
Sign inDemoInstall

chromecast-api

Package Overview
Dependencies
76
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chromecast-api

Chromecast streaming module all in JS


Version published
Weekly downloads
391
decreased by-30.18%
Maintainers
1
Install size
19.4 MB
Created
Weekly downloads
 

Readme

Source

chromecast-api

NPM Version Travis Build Standard - Javascript Style Guide

chromecast-api is a javascript client library for googlecast's remote playback protocol to play any (compatible) content in the Chromecast device.

Supported media formats: MP4, JPG and PNG files.

Installation

npm install chromecast-api 

Usage

var ChromecastAPI = require('chromecast-api')

var browser = new ChromecastAPI.Browser()

browser.on('deviceOn', function (device) {
  var urlMedia = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4';

  device.play(urlMedia, 0, function () {
    console.log('Playing in your chromecast')

      setTimeout(function () {
        //Pause the video
        device.pause(function () {
          console.log('Paused')
        })
      }, 20000)

      setTimeout(function () {
        //Stop video
        device.stop(function () {
          console.log('Stopped')
        })
      }, 30000)

      setTimeout(function () {
        //Close the streaming
          device.close(function () {
            console.log('Closed')
          })
      }, 40000)
  })
})

Subtitles and Cover

To include subtitles and a cover image, use an Object instead of a string in the play method:


var ChromecastAPI = require('chromecast-api')

var browser = new ChromecastAPI.Browser()

var media = {
  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-notation
    foregroundColor: '#FFFFFFFF', // see http://dev.w3.org/csswg/css-color/#hex-notation
    edgeType: 'OUTLINE', // can be: "NONE", "OUTLINE", "DROP_SHADOW", "RAISED", "DEPRESSED"
    edgeColor: '#000000FF', // see http://dev.w3.org/csswg/css-color/#hex-notation
    fontScale: 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: '#00000000', // see http://dev.w3.org/csswg/css-color/#hex-notation
    //windowRoundedCornerRadius: 10, // radius in px
    //windowType: 'ROUNDED_CORNERS' // can be: "NONE", "NORMAL", "ROUNDED_CORNERS"
  }
}

browser.on('deviceOn', function (device) {

  // Starting to play Big Buck Bunny exactly at second #0 with example subtitles and cover
  device.play(media, 0, function () {
    console.log('Playing in your chromecast')

      setTimeout(function () {
        device.subtitlesOff(function (err,status) {
          if (err) console.log('Subtitles off: ERROR')
            else console.log('Subtitles off: SUCCESS')
        })
      }, 20000)

      setTimeout(function () {
        device.changeSubtitles(1, function (err, status) {
          if (err) console.log("Subtitles restored and in spanish: ERROR")
          else console.log("Subtitles restored and in spanish: SUCCESS")
        })
      }, 25000)

      setTimeout(function () {
        device.pause(function () {
          console.log('Paused: SUCCESS')
        })
      }, 30000)

      setTimeout(function () {
        device.unpause(function () {
          console.log('Resumed: SUCCESS')
        })
      }, 40000)

      setTimeout(function () {
        device.changeSubtitles(0, function (err, status) {
          if (err) console.log("Change to english subtitles: ERROR")
          else console.log("Change to english subtitles: SUCCESS")
        })
      }, 45000)

      setTimeout(function () {
        console.log('Increase subtitles size')
        device.changeSubtitlesSize(2, function (err, status) {
          if (err) console.log("Increase subtitles: ERROR")
          else console.log("Increase subtitles: SUCCESS")
        })
      }, 50000)

      setTimeout(function () {
        device.seek(10,function (err) {
          if (err) console.log('Seek forward: ERROR')
          else console.log('Seek forward: SUCCESS')
        })
      }, 60000)

      setTimeout(function () {
        device.changeSubtitlesSize(1.2, function (err, status) {
          if (err) console.log("Decrease subtitles: ERROR")
          else console.log("Decrease subtitles: SUCCESS")
        })
      }, 70000)

  })
})

Acknowledgement

This is based on chromecast-js by @guerrerocarlos

Keywords

FAQs

Last updated on 19 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc