google-castgoogle-cast-sdk

Setting playbackRate from a chromecast websender


Android and iOS have a setPlaybackRate method, but the Web Sender API doesn't have this. How can I accomplish this using sendMessage? Is it something like this? But what is the type of message?

playerTarget.setHalfSpeed = function (){
    var media = castSession.getMediaSession();
    castSession.sendMessage("urn:x-cast:com.google.cast.media",{
        type: "THEWHATNOW",
        playbackRate: 0.5,
        mediaSessionId: media.mediaSessionId
    });
}.bind(this);

I see messages listed here: https://developers.google.com/cast/docs/reference/messages but then in the examples I see a message type of "SKIP_AD" which isn't documented anywhere. All I want to be able to do is set the playback rate during playback when casting as a websender.

I see the message type here: https://developers.google.com/cast/docs/reference/web_receiver/cast.framework.messages.SetPlaybackRateRequestData But what is the namespace for that to send in the sendMessage call?


Solution

  • For anyone else who stumbles upon this, here is what worked for me:

    playerTarget.setHalfSpeed = function (){
        var media = castSession.getMediaSession();
        castSession.sendMessage("urn:x-cast:com.google.cast.media",{
            type: "SET_PLAYBACK_RATE",
            playbackRate: 0.5,
            mediaSessionId: media.mediaSessionId,
            requestId: 2
        }).then(
            function (a) { console.log('Set playback rate success'); },
            function (errorCode) {
                console.log('Set playback rate error: ' + errorCode);
            });
    }.bind(this);
    

    The requestId doesn't seem to matter as its a transit variable.