Chromecast 自定义接收器不会暂停音频元素

Chromecast custom receiver doesn't pause audio element

现在我正在 iOS 上开发发送器,它在我的自定义接收器上正确播放音频但是当我在发送器上发送暂停消息时

self.mediaControlChannel.pause;

我可以看到(从调试中)自定义接收器收到一条消息

[ 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"}

但它不会暂停我的音频元素。此后音频继续播放。

这就是我创建音频元素实例和处理转换的方式:

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");
    }
}

需要启动receiver manager,调用:

window.castReceiverManager.start();