ユーザがビデオ内の新しい位置に移動/スキップを開始すると、テキストにより警告します:
var vid = document.getElementById("myVideo");
vid.onseeking = function() {
alert("Seek operation began!");
};
Try it Yourself ❯
他の "Try it Yourself" の例が下にあります。
を開始するときに求めているイベントが seeking イベントは、ユーザがオーディオ/ビデオ内の新しい位置に、移動/スキップを開始すると発生します。
チップ: seeking イベントは、seeked イベントの逆です。
チップ: 現在の再生位置を取得するには、オーディオ/ビデオ・オブジェクトの currentTime プロパティを使用します。
表中の数字は、イベントを完全にサポートした最初のブラウザ・バージョンを指定しています。
| イベント | |||||
|---|---|---|---|---|---|
| seeking | Yes | 9.0 | Yes | Yes | Yes |
HTML の場合:
<audio|video onseeking="myScript">Try it
JavaScript の場合:
audio|video.onseeking=function(){myScript};Try it
JavaScriptで、addEventListener() メソッドを使用する場合:
audio|video.addEventListener("seeking", myScript);Try it
注: addEventListener() メソッドは、 Internet Explorer 8 以前のバージョンではサポートしていません。
| サポートする HTML タグ: | <audio> および <video> |
|---|---|
| サポートするJavaScript オブジェクト: | Audio, Video |
この例では、seeking イベントと seeked イベントの違いを示しています。
<video onseeking="myFunction()" onseeked="mySecondFunction()">
Try it Yourself ❯
ユーザが新しい位置にスキップを開始したときに、現在の再生時間位置を表示するために Video オブジェクトの currentTime プロパティを使用します:
// Get the <video> element with id="myVideo"
var vid =
document.getElementById("myVideo");
// Attach a seeking event to the
<video>, and execute a function if a seek operation begins
vid.addEventListener("seeking", myFunction);
function myFunction() {
// Display the current position of the <video> in a p element with id="demo"
document.getElementById("demo").innerHTML = vid.currentTime;
}
Try it Yourself ❯
ユーザがオーディオ内の新しい位置に移動/スキップを開始すると、テキストにより警告します:
var aud = document.getElementById("myAudio");
aud.onseeking = function() {
alert("Seek operation began!");
};
Try it Yourself ❯
HTML オーディオ/ビデオ DOM リファレンス