2016-09-01 15 views
5

ページに複数の動画があります。HTMLビデオにバッファリングを追加する方法

<div class="row text-center"> 
    <video width="320" height="240" controls class="myvideo"> 
     <source src="http://www.html5videoplayer.net/videos/toystory.mp4" type="video/mp4"> 
     Your browser does not support the video tag. 
    </video> 
</div> 

<div class="row text-center"> 
    <video width="320" height="240" controls class="myvideo"> 
     <source src="http://www.html5videoplayer.net/videos/fantasy.mp4" type="video/mp4"> 
     Your browser does not support the video tag. 
    </video> 
</div> 

バッファリングイベントを追加します。また、ビデオ1をクリックすると、ビデオ2(再生している場合)が自動的に停止するはずです。どうすればこれを達成できますか?彼らは共通のクラスを持っています。私はそれらとidsを実装する必要がありますか?あなたの動画へ

答えて

1

ギブのIds:

function videoPlay1() { 
    var video1 = document.getElementById("myVideoOne"); 
    var video2 = document.getElementById("myVideotwo"); 

    if (video1.paused) { 
     video1.play(); 
     video2.pause(); 
    } else { 
     video1.pause(); 
     video2.pause(); 
    } 
} 

function videoPlay2() { 
    var video1 = document.getElementById("myVideoOne"); 
    var video2 = document.getElementById("myVideotwo"); 

    if (video2.paused) { 
     video2.play(); 
     video1.pause(); 
    } else { 
     video1.pause(); 
     video2.pause(); 
    } 
} 

例:あなたはvideoPlay1とvideoPlay2関数内にこれを使用することができ、自動的にストーピングため

var vid = document.getElementById("myVideoOne"); 
alert("Start: " + vid.buffered.start(0) 
    + " End: " + vid.buffered.end(0)); 

var vid = document.getElementById("myVideoTwo"); 
alert("Start: " + vid.buffered.start(0) 
    + " End: " + vid.buffered.end(0)); 

:バッファリングのための

<video width="320" height="240" controls class="myvideo" id="myVideoOne"> 
<video width="320" height="240" controls class="myvideo" id="myVideoTwo"> 

: myVideoOneのローダ​​ーを設定するには、このjqueryを使用します: css:

video.loading { 
    background: black url(/yourGifImg.gif) center center no-repeat; 
} 

jqueryの:

$('#myVideoOne').on('loadstart', function (event) { 
    $(this).addClass('loading') 
}); 
$('#myVideoOne').on('canplay', function (event) { 
    $(this).removeClass('loading') 
}); 
+0

私は自分の動画にローダーを取得傾けます。 –

+0

ビデオローダー用のjqueryを追加しました。そのためにgifを使用できます – Simo

関連する問題