以下はテストされていません。 1つは事前に - 埋め込まれたYouTubeのiframeと同じようにhtml5動画要素を処理することはできません。 ビデオ要素がある場合は、直接ビデオ要素とやりとりできます。再生、一時停止、終了のイベントハンドラを使用してリクエストを処理します。可能な解決策は、このような何かを見ることができる:あなたが直接埋め込ま要素を制御することはできませんので、あなたがyoutube APIで作業する必要があります
$(function() {
var refreshId;
// collection of all video elements on your page
var videos = $('video');
// disable reload by clearing the interval
function blockReload() {
clearInterval(refreshId);
}
// your existing reload function
function startReload() {
refreshId = setInterval(function() {
$("#updates").load('updates.php' + '?randval=' + Math.random());
}, 30000);
}
// loop over all video elements on your page and bind
// three event handlers, one for playing, one for pausing
// and one for an ended video.
videos.each(function() {
this.addEventListener('playing', blockReload);
this.addEventListener('paused', startReload);
this.addEventListener('ended', startReload);
});
});
。
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '360'
width: '640',
videoId: 'YOURVIDEOID',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
:
// This code loads the IFrame Player API code asynchronously.
// you could also use a normal script tag in that case you would load
// the lib each time.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
次はあなたがスクリプトライブラリを介してビデオを読み込む: 代わりユーチューブからのiframeを使用して、あなたは(APIページから例)このようなビデオをロードするためにAPIを使用します
は今、あなたはユーチューブビデオと対話することができます
function onPlayerStateChange(event) {
// check if video is running...
if (event.data == YT.PlayerState.PLAYING) {
// disable interval
blockReload();
} else {
// restart interval
startReload();
}
}
APIに見て、https://developers.google.com/youtube/iframe_api_reference、ケースビデオに明確な間隔が再生されています。 –