<script src="https://www.youtube.com/iframe_api"></script> <script> var movie01 var movie02 function onYouTubeIframeAPIReady() { movie01 = new YT.Player('movie01', { height: '315', width: '560', videoId: 'LBJ0K6J_Xbg', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange }, playerVars: { "rel":0, // 関連動画の有無(default:1) } }); movie02 = new YT.Player('movie02', { height: '315', width: '560', videoId: '9-yHfgg91oY', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange }, playerVars: { "rel":0, // 関連動画の有無(default:1) } }); } // 4. The API will call this function when the video player is ready. function onPlayerReady(event) { event.target.mute(); } // 5. The API calls this function when the player's state changes. // The function indicates that when playing a video (state=1), // the player should play for six seconds and then stop. var done = false; function onPlayerStateChange(event) { // if (event.data == YT.PlayerState.PLAYING && !done) { // setTimeout(stopVideo, 6000); // done = true; // } } function stopVideo() { player.stopVideo(); } </script> <body> <div id="movie01"></div> <div id="movie02"></div> </body>