我一直在谷歌演员sdk的接收器上工作。我有多个youtube视频和mp4视频在云端,我有一个应用程序,有这些视频。我能够投射youtube视频但是当我点击mp4链接时,我无法获得对接收器的控制权。 有人帮忙吗?`
var player;
function onYouTubePlayer(videoId) {
player = new YT.Player('player', {
height: '720',
width: '1280',
videoId: videoId,
playerVars: { autoplay:1, controls:1, showinfo: 0, rel: 0, showsearch: 0, iv_load_policy: 3, enablejsapi:1,listType:'playlist',
list: playlist},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': catchError
}
});
}
var done = false;
var playlist;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
done = true;
} else if (event.data == YT.PlayerState.ENDED) {
event.target.destroy();
location.reload();
}else if(event.data == YT.PlayerState.PAUSED){
location.reload();
}
}
function onPlayerReady(event) {
//if(typeof(SONG.getArtistId()) == undefined)
//{
// console.log("undefineeeed");
//}
player.addEventListener('onStateChange', function(e) {
console.log('State is:', e.data);
});
event.target.playVideo();
}
function catchError(event)
{
if(event.data == 100) console.log("This Video does not exist!!");
}
function stopVideo() {
player.stopVideo();
}
/**
* Called when we receive a LOAD message. Calls load().
*
* @see sampleplayer#load
* @param {cast.receiver.MediaManager.Event} event The load event.
* @private
*/
sampleplayer.CastPlayer.prototype.onLoad_ = function(event) {
this.log_('onLoad_');
this.log_(event.data);
// handler for the CastMessageBus message event
this.messageBus.onMessage = function(event) {
this.log_('Message [' + event.senderId + ']: ' + event.data);
// display the message from the sender
// inform all senders on the CastMessageBus of the incoming message event
// sender message listener will be invoked
this.messageBus.send(event.senderId, event.data);
}
var videoId = event.data.media.contentId.split("?v=")[1];
if(event.data.media.contentId.includes("youtube.com")){
if (typeof(YT) == 'undefined' || typeof(YT.Player) == 'undefined') {
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
window.onYouTubePlayerAPIReady = function() {
onYouTubePlayer(videoId);
};
} else {
onYouTubePlayer(videoId);
}
}else{
}
this.cancelDeferredPlay_('new media is loaded');
this.load(new cast.receiver.MediaManager.LoadInfo(
/** @type {!cast.receiver.MediaManager.LoadRequestData} */ (event.data),
event.senderId));
};

`