2013-12-20 34 views
10

我做視頻網站在HTML5與<視頻>如何預先加載我的網站和其他網頁中的所有視頻?

在從光盤網站淡入淡出和非常漂亮的我的電腦,但在我的服務器我等待太久的每一頁,因爲視頻開始預載。

有你有任何想法如何站點

/Index.html 
/Portfolio.html 
/Contact.html 

preloade當我們去的index.html?你知道,我們去了Index.html,我們看到了procent preloader,在這個時候我們加載/Index.html/Portfolio.html /Contact.html等等。當它完成時,所有的電影都被加載到緩存瀏覽器和它工作的網站中實時 - 點擊contact.html,我看到播放電影(不等待預載視頻)。

任何想法如何使它? 非常感謝,Arleta

回答

1

您可以將您擁有的不同html頁面(demo-big-counter.html,demo-circular.html)組合到一個HTML頁面中,並將內容分隔到不同的標籤中(您可以使用它來實現標籤頁 - http://getbootstrap.com/javascript/#tabs )。

將您的視頻添加到最初隱藏的選項卡中,只要主html文件打開,它們就會開始加載。

1

我會嘗試JavaScript的東西,並將所有頁面設置爲一個。您無法預加載另一個HTML文件中的內容。

+0

也許這是任何想法做呢? http://thinkpixellab.com/pxloader/#plugins 任何測試? –

0

檢查這個博客,是非常有用的http://dinbror.dk/blog/how-to-preload-entire-html5-video-before-play-solved/#comment-202625

我已經如下

var percentage = 0; 


function update_progress(e) { 
    if (e.lengthComputable) { 



      percentage = Math.round((e.loaded/e.total) * 100) - 50; 
      console.log("percent " + percentage + '%'); 

    } else { 
     console.log("Unable to compute progress information since the total size is unknown"); 
    } 
} 

function transfer_complete(e) { 
    console.log("The transfer is complete."); 

} 

function transfer_failed(e) { 
    console.log("An error occurred while transferring the file."); 
} 

function transfer_canceled(e) { 
    console.log("The transfer has been canceled by the user."); 
} 

function downloadVideo() { 

    var xhttp; 
    if (window.XMLHttpRequest) { 
     xhttp = new XMLHttpRequest(); 
    } //code for modern browsers} 
    else { 
     xhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } // code for IE6, IE5  
    xhttp.onprogress = update_progress; 
    xhttp.responseType = 'blob'; 
    xhttp.addEventListener("load", transfer_complete, false); 
    xhttp.addEventListener("error", transfer_failed, false); 
    xhttp.addEventListener("abort", transfer_canceled, false); 
    xhttp.onreadystatechange = function() { 
     if (xhttp.readyState == 4 && xhttp.status == 200) { 
      var videoBlob = xhttp.response; 
      var vid = URL.createObjectURL(videoBlob); // IE10+ 
      // Video is now downloaded 
      // and we can set it as source on the video element 

       $('#myVideo').attr('src', vid); 

     } 
    }; 

    xhttp.open("GET", "media/2.mp4", true); 
    xhttp.send(); 


} 
相關問題