1

Right now I'm developing a sender on iOS, it's playing an audio correctly on my custom receiver but when I send a pause message on sender

self.mediaControlChannel.pause;

I can see(from debug) that custom receiver receives a message

[ 22.169s] [cast.receiver.IpcChannel] Received message: {"data":"{\"type\":\"PAUSE\",\"requestId\":9,\"mediaSessionId\":2}","namespace":"urn:x-cast:com.google.cast.media","senderId":"5:589F942A-AB58-42F3-9B94-3674DB0428D4"}

but it doesn't pause my audio element. Audio keeps playing after this.

This is how I'm creating an instance of my audio element and handling casting:

window.onload = function() {
    cast.receiver.logger.setLevelValue(0);

    window.mediaManager = new cast.receiver.MediaManager(audio);

    window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
    console.log('Starting Receiver Manager');

    // handler for the 'ready' event
    window.castReceiverManager.onReady = function(event) {
    console.log('Received Ready event: ' + JSON.stringify(event.data));
      window.castReceiverManager.setApplicationState("Application status is ready...");
        };

    window.mediaManager.onMetadataLoaded = function(info) {
     console.log('Metadata Received');
    var media = info.message.media;
    songUrl = media.contentId;
    $('.media').attr("src", songUrl);

    console.log("song url " + songUrl)
    console.log(info);

    this.onLoadSuccess();
}

    // handler for 'senderconnected' event
    window.castReceiverManager.onSenderConnected = function(event) {
      console.log('Received Sender Connected event: ' + event.data);
      console.log(window.castReceiverManager.getSender(event.data).userAgent);
    };

    // handler for 'senderdisconnected' event
    window.castReceiverManager.onSenderDisconnected = function(event) {
      console.log('Received Sender Disconnected event: ' + event.data);
      if (window.castReceiverManager.getSenders().length == 0) {
        window.close();
      }
    };

    // handler for 'systemvolumechanged' event
    window.castReceiverManager.onSystemVolumeChanged = function(event) {
      console.log('Received System Volume Changed event: ' + event.data['level'] + ' ' +
      event.data['muted']);
    };

    window.castReceiverManager.onSenderDisconnected = function (event) {
        console.log("Sender disconnected");
        if (window.castReceiverManager.getSenders().length == 0 &&
        event.reason == cast.receiver.system.DisconnectReason.REQUESTED_BY_SENDER) {
            window.close();
        }
    };

    window.mediaManager.onLoadSuccess = function() {
        console.log("load success");
        var totalTime = audio.duration;
        console.log(totalTime);
        $(".final-time").text(formatDuration(totalTime));
    }

    window.castReceiverManager.start({maxInactivity: 6000});

    audio.addEventListener('timeupdate', updateProgress, false);

    window.castReceiverManager.onPlay = function() {
        console.log("event 1")
    }

    window.castReceiverManager.onPause = function() {
        console.log("event 2");
    }
}
4

1 回答 1

1

您需要启动接收器管理器,调用:

window.castReceiverManager.start();
于 2016-02-03T16:56:02.693 回答