thibauts / node-castv2-client

A Chromecast client based on the new (CASTV2) protocol
MIT License
646 stars 92 forks source link

How would I set the volume on a chromecast audio? #72

Open dk253 opened 7 years ago

dk253 commented 7 years ago

Hey, Thanks for the library! I'm trying to set the volume on a Chromecast Audio. Actually I'm trying to write a web app to control all the volumes on all of the chromecasts at once. How would I use your lib to do that?

Thanks!

jonferreira commented 6 years ago
if(typeof volume !== 'undefined') {

            if(volume > 0){
                var obj = { level: volume/100 };
            } else {
                var obj = { muted: true };
            }

              client.setVolume(obj, function(err, newvol){
                if(err) {
                    console.log("there was an error setting the volume")
                    node.error("Chromecast error: there was an error setting the volume");
                    msg.error = "there was an error setting the volume";
                    node.send(msg);
                    return node.status({
                      shape: "dot",
                      fill: "red",
                      text: "error: there was an error setting the volume" 
                    });
                }
                console.log("volume changed to %s", Math.round(newvol.level * 100))
            });

          }