2016-09-01 22 views
5

Mam wiele filmów na stronie.Jak dodać buforowanie do mojego wideo 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> 

Chcę dodać do nich zdarzenia buforujące. Ponadto, gdy kliknę wideo 1, wideo 2 (jeśli gra) powinno automatycznie się zatrzymać. Jak mogę to osiągnąć? Mają wspólną klasę. Czy muszę zaimplementować identyfikatory ids?

Odpowiedz

1

dać identyfikatory do swoich filmów:

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

do buforowania:

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)); 

dla stoping automatycznie można użyć to w twoich videoPlay1 i videoPlay2 funkcji:

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(); 
    } 
} 

przykład: aby ustawić moduł ładujący dla myVideoOne, możesz użyć tego 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

nie mogę dostać ładowarka z moich filmów. –

+0

Dodałem jquery do programu ładującego wideo, możesz użyć do tego gifa – Simo

Powiązane problemy