Videojs視頻外掛程式在React中的應用

來源:互聯網
上載者:User

標籤:height   代碼   set   web   style   class   mil   jquery   效果   

1.介紹video.js視頻外掛程式

  1.1 簡單介紹

    Video.js是一個通用的在網頁上嵌入視頻播放器的JS庫,支援電腦端和移動端。Video.js自動檢測瀏覽器對Html5的支援情況,如果不支援Html5,則自動使用Flash播放器。外掛程式下載,如要支援ie低版本,點擊此處下載。

  1.2 入門使用

    (1)載入CSS檔案和JS檔案

    

   (2)在頁面添加Html5的Video標籤

   

    id: 就是id。

    class:  video-js與vjs-default-skin,前者是JS識別,後者載入CSS,都是必須的。

    poster: 播放的初始圖。

    data-setup: 頁面準備完成即自動載入。

    source: 指向視頻。這裡提供三種視頻格式,mp4/webm/ogg。

    (3)簡單應用Video.js

    

    將上面設定自動播放代碼添加到Html中代碼後面。下面提供幾個常用的方法:
   
    擷取對象:var myPlayer = vjs(“my_video_1″);
   
    播放: myPlayer.play();

    暫停: myPlayer.pause();

    擷取進度條:var whereYouAt = myPlayer.currentTime();

   設定播放進度: myPlayer.currentTime(120);

   緩衝: var whatHasBeenBuffered = myPlayer.buffered();

   百分比的緩衝: var howMuchIsDownloaded = myPlayer.bufferedPercent();

    聲音大小(0-1之間):var howLoudIsIt = myPlayer.volume();

    設定聲音大小:myPlayer.volume(0.5);

    設定寬度:myPlayer.width(640);

   設定高度:myPlayer.height(480);

   全屏:myPlayer.enterFullScreen();

   添加事件:var myFunc = function(){

          // Do something when the event is fired
         };
        myPlayer.addEvent(“eventName”, myFunc);
    刪除事件:myPlayer.removeEvent(“eventName”, myFunc);

    註:需要瞭解更詳細的使用方法,可以在Video.js官網查看。

2.項目中實際應用

  項目採用React前端架構技術,結合前後台技術背景。Video.js在項目中的具體應用如下:

  (1)非同步載入CSS檔案和JS檔案,並且設定視頻的尺寸大小、是否自動播放。

  

  (2)定義實體,供後台返回資料可用。

  

  (3)書寫Html。source指向的三種視頻格式,放在一個數組裡面。

  

  點擊按鈕,資料重新整理。

  

  (4)最後效果

  

Videojs視頻外掛程式在React中的應用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.