다음은 현재 수신기에서 사용중인 코드입니다. 메시지 핸들링 (양방향)은 실패하고, 놓치고, 나는 그것을 통해 현재 작업하고 있습니다 ...하지만 iFrame 라이브러리의 로딩, 비디오의 임베딩 등은 모두 작동합니다. 귀하의 목적에 맞지 않을 경우 귀하의 설정이 어떻게 다른지 조사 할 수 있습니다. 나는 그것이 도움이 될만한 의견을 추가하려고 노력했다.
<html>
<head>
<script src="https://www.gstatic.com/cast/js/receiver/1.0/cast_receiver.js">
</script>
<script type="text/javascript">
// first create our receiver object and our channel handler
var receiver = new cast.receiver.Receiver('{YOUR_APP_ID}', ['ChromecastYoutube'],"",5);
var ytChannelHandler = new cast.receiver.ChannelHandler('ChromecastYoutube'); // 'using 'ChromecastYoutube' as my dev namespace. Wouldn't really be that in production.
ytChannelHandler.addChannelFactory(receiver.createChannelFactory('ChromecastYoutube'));
ytChannelHandler.addEventListener(
cast.receiver.Channel.EventType.MESSAGE,
onMessage.bind(this)
);
receiver.start();
window.addEventListener('load', function() { // we won't try to load the iframe libraries until the chromecast window is fully loaded.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
});
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '562',
width: '1000',
videoId: 'jLlSqucqXB0',
playerVars: { 'autoplay': 0, 'controls': 0 },
events: {
'onReady': onPlayerReady,
'onPlayerStateChange': onStateChange
}
});
}
function onPlayerReady(event) {
document.getElementById('annotation').innerHTML="We're ready to go";
}
function onStateChange(event) {
switch (event.data) {
case YT.PlayerState.ENDED:
// TODO let sender know we're done, then close casting
break;
case YT.PlayerState.PLAYING:
// TODO let sender know we're playing
break;
case YT.PlayerState.PAUSED:
// TODO let sender know we're paused
break;
}
}
function onMessage(event) { // currently, any one of these will work, but subsequent ones seem to falter. Investigating...
ytBindings={"playVideo":player.playVideo(),"pauseVideo":player.pauseVideo(),"stopVideo":player.stopVideo(),"getStatus":player.getPlayerState()}
ytBindings[event.message];
}
</script>
<style>
#wrapper {
width: 1000px;
margin: 10px auto;
text-align: center;
}
#annotation {
color: #ffffcc;
font-size: 200%;
margin-top:25px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="player"></div>
<div id="annotation"></div>
</div>
</body>
</html>
iFrame API를 사용하는 수신기를 성공적으로 만들었으며 아직 시도한 동영상에 문제가 없었습니다. 어떤 비디오 ID로 오류가 발생 했습니까? 따라서 리시버에서 해당 비디오 ID를 시도해 볼 수 있습니다. 성공한 경우 코드를 대답으로 공유 할 수 있습니까? – jlmcdonald
나는 하나 하나 시도했다. 예를 들어, youtube api의 참조 예 - 'M7lc1UVf-VE' – milleph
하지만 설정/초기화 만하면됩니다. 만약 당신이 매우 도움이 될 몇 가지 코드를 게시 할 수 있습니다. – milleph