现在我正在iOS上开发一个发送器,它在我的自定义接收器上正确播放音频,但是当我在发送器上发送暂停消息时
self.mediaControlChannel.pause;
我可以看到(从调试)自定义接收器收到消息
[ 22.169秒] [投射.接收器.Ipc频道]收到的消息: {"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");
}
}
您需要启动接收方管理器,调用:
window.castReceiverManager.start();