2015-06-09 154 views

回答

0

你必須使用媒體來源擴展(MSE)來控制。否則,瀏覽器會做它認爲最好的,你將無法強制或保證瀏覽器會加載100%的視頻。

查看MSE here (intro)here (specs)here (use-case)

0

創建JS元素:

var obj = document.createElement('video'); 
$(obj).attr('id', 'example_video_test'); 
$(obj).attr('width', '640'); 
$(obj).attr('data-height', '264'); 
$(obj).attr('controls', ' '); 
$(obj).attr('poster', '../oceans-clip.jpg'); 


source = document.createElement('source'); 
$(source).attr('type', 'video/mp4'); 
$(source).attr('src', '../oceans-clip.mp4'); 
$(obj).append(source); 


if (document.getElementById('example_video_test').readyState === 4) { 
    // it's loaded 
} 

PS:此代碼是未經測試可能需要一些改變

readyState == 4 ==> Enough data is available—and the download rate is high enough—that the media can be played through to the end without interruption.