Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the getVolume function #92

Open
simonravel opened this issue Jun 20, 2019 · 1 comment
Open

How to use the getVolume function #92

simonravel opened this issue Jun 20, 2019 · 1 comment

Comments

@simonravel
Copy link

I tried to use this function:

const GoogleCastClient = require("castv2-client").Client;
const DefaultMediaReceiver = require("castv2-client").DefaultMediaReceiver;
const client = new GoogleCastClient();
var 'some_ip' = '192.168.0.x' //just an example

client.connect(,() => {
    client.launch(DefaultMediaReceiver, (err, player) => {
            const media = {
              contentId: url,
              contentType: "audio/mp3",
              streamType: "BUFFERED"
            };

          player.load(media, { autoplay: true }, (err, status) => {
              client.close();
              console.log(`Pushed to device at ${some_ip}`);
            });
      });

   client.getVolume('volume', function(vol){
          console.log(vol)
   })
    
   client.on("error", err => {
        reject(`Google Cast Client error:\n${err}`);
        client.close();
      });

});

Which results in: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getVolume' of null

@daaru00
Copy link

daaru00 commented Jan 18, 2020

Hi @simonravel,

I think the error is here:

client.getVolume('volume', function(vol){ 

you don't have to pass any parameters (except callback function), the correct method's call is:

this.client.getVolume(function (err, vol) { ... })

also pay attention to first callback parameters, is an error object (null if no error is released) not the current volume infos.

Here an example:

this.client.getVolume(function (err, vol) {
    if (err) {
        console.error(err) // handle error
        return
    }
    console.log(vol) // {"controlType":"attenuation","level":0.7999999523162842,"muted":false,"stepInterval":0.05000000074505806}
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants