欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于vue的video播放器的實(shí)現(xiàn)示例

 更新時(shí)間:2021年02月19日 10:33:01   作者:地瓜哥  
這篇文章主要介紹了基于vue的video播放器的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

當(dāng)現(xiàn)有video播放器不能滿足需求時(shí),需要自己對(duì)video進(jìn)行封裝。

video事件

  • loadstart: 在視頻開(kāi)始加載時(shí)觸發(fā),給currentTime賦值(歷史播放記錄或0)。
  • durationchange: 元信息已載入或已改變,視頻的長(zhǎng)度發(fā)生了改變。獲取到視頻長(zhǎng)度(duration,并給currentTime賦值(歷史播放記錄或0))。
  • playing: 在視頻開(kāi)始播放時(shí)觸發(fā)(不論是初次播放、在暫停后恢復(fù)、或是在結(jié)束后重新開(kāi)始)。
  • pause: 播放暫停時(shí)觸發(fā)。
  • timeupdate: currentTime改變, 更新播放進(jìn)度。處理播放進(jìn)度條
  • seeked: 指定播放位置
  • waiting: 緩沖
  • ended: 播放結(jié)束, 重置狀態(tài)
  • WeixinJSBridgeReady: 在微信中使用video,需要監(jiān)聽(tīng)weixinJSBridgeReady事件, 在回調(diào)函數(shù)里執(zhí)行play()命令。

直播協(xié)議

HLS(HTTP Live Streaming)由Apple提出的直播流協(xié)議。IOS和高版本Android都支持HLS。HLS主要由.m3u8和.ts兩種播放文件。HLS具有高兼容性,高可擴(kuò)展性,但會(huì)直播延時(shí)。HLS協(xié)議是將直播流分成一段一段的小段視頻去下載播放的,所以假設(shè)列表里面的包含5個(gè)ts文件,每個(gè)ts文件包含5秒的視頻內(nèi)容,那么整體的延遲就是25秒。

RTMP(Real Time Messaging Protocol)是Macromedia開(kāi)發(fā)的一套視頻直播協(xié)議,現(xiàn)在屬于Adobe。RTMP基于flash無(wú)法在IOS的瀏覽器里播放,但是實(shí)時(shí)性比HLS要好。

HTTP-FLV針對(duì)于FLV視頻格式做的直播分發(fā)流,延時(shí)低。但移動(dòng)端不支持。

結(jié)論:HTTP-FLV延時(shí)低,優(yōu)先使用。若設(shè)備不支持HTTP-FLV,使用flv.js。若設(shè)備不支持flv.js,則使用HLS,但HLS延遲大。

封裝video

/** HTML **/
<div class="video">
 <!-- video player -->
 <video
  class="video__player"
  ref="videoPlayer"
  preload="auto"
  :autoplay="options.autoplay"
  :muted="options.muted"
  webkit-playsinline="true"
  playsinline="true"
  x-webkit-airplay="allow"
  x5-video-player-type="h5-page"
  x5-video-orientation="portraint"
  style="object-fit:cover;"
 >
  <source :src="options.src" />
 </video>

 <!-- video poster -->
 <div
  v-show="showPoster"
  class="video__poster"
  :style="{'background-image': 'url(' + options.pic + ')'}"
 ></div>

 <!-- video loading -->
 <div v-show="showLoading" class="video__Loading">
  <span class="video__Loading-icon"></span>
 </div>

 <!-- video pause -->
 <div @click="handleVideoPlay" class="video__pause">
  <span v-show="!videoPlay" class="video__pause-icon"></span>
 </div>
</div>
/** js**/
props: {
 options: {
  type: Object,
  default: () => {}
 }
},
data() {
 return {
  videoPlay: false, // 是否正在播放
  videoEnd: false, // 是否播放結(jié)束
  showPoster: true, // 是否顯示視屏封面
  showLoading: false, // 加載中
  currentTime: 0, // 當(dāng)前播放位置
  currentVideo: {
   duration: this.options.duration
  },

 }
},
mounted() {
 this.videoPlayer = this.$refs.videoPlayer;
 this.videoPlayer.currentTime = 0;
 
 this.videoPlayer.addEventListener("loadstart", e => {
   this.videoPlayer.currentTime = (this.options.playProcess > 0) ? this.options.playProcess : 0;
 });
 
  // 獲取到視頻長(zhǎng)度
 this.videoPlayer.addEventListener("durationchange", e => {
  this.currentVideo.duration = this.videoPlayer.duration;
  // 存在播放歷史記錄
  this.videoPlayer.currentTime = (this.options.playProcess > 0) ? this.options.playProcess : 0;
 });
 
 this.videoPlayer.addEventListener("playing", e => {
  this.showPoster = false;
  this.videoPlay = true;
  this.showLoading = false;
  this.videoEnd = false;
 });
 
 // 暫停
 this.videoPlayer.addEventListener("pause", () => {
  this.videoPlay = false;
  if (this.videoPlayer.currentTime < 0.1) {
   this.showPoster = true;
  }
  this.showLoading = false;
 });
 
 // 播放進(jìn)度更新
 this.videoPlayer.addEventListener("timeupdate", e => {
   this.currentTime = this.videoPlayer.currentTime;
  },
  false
 );

 // 指定播放位置
 this.videoPlayer.addEventListener("seeked", e => {
 });

 // 緩沖
 this.videoPlayer.addEventListener("waiting", e => {
  this.showLoading = true;
 });
 
 // 播放結(jié)束
 this.videoPlayer.addEventListener("ended", e => {
  // 重置狀態(tài)
  this.videoPlay = false;
  this.showPoster = true;
  this.videoEnd = true;
  this.currentTime = this.currentVideo.duration;
 });
 
 // 監(jiān)聽(tīng)weixinJSBridgeReady事件,處理微信不能自動(dòng)播放。但并不全部適用,加了暫停按鈕,手動(dòng)播放。
 document.addEventListener('WeixinJSBridgeReady', () => { 
  this.videoPlayer.play();
 }, false);
},
methods: {
 handleVideoPlay() {
  if (this.videoPlayer.paused) { // 播放
   if(this.videoEnd) { // 重播
    this.currentTime = 0;
    this.videoPlayer.currentTime = 0;
   }
   this.videoPlayer.play();
   this.videoPlay = true;
  } else { // 暫停
   this.videoPlayer.pause();
   this.videoPlay = false;
  }
 }
}

[參考文章]:

到此這篇關(guān)于基于vue的video播放器的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)vue video播放器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue中使用heatmapjs的示例代碼(結(jié)合百度地圖)

    vue中使用heatmapjs的示例代碼(結(jié)合百度地圖)

    這篇文章主要介紹了vue中使用heatmapjs的示例代碼(結(jié)合百度地圖),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • nuxt.js 緩存實(shí)踐

    nuxt.js 緩存實(shí)踐

    這篇文章主要介紹了nuxt.js 緩存實(shí)踐,nuxt 的緩存可以分為 組件級(jí)別緩存 , API級(jí)別緩存 以及 頁(yè)面級(jí)別緩存,本文就詳細(xì)的介紹了這三種緩存,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Vue.js教程之a(chǎn)xios與網(wǎng)絡(luò)傳輸?shù)膶W(xué)習(xí)實(shí)踐

    Vue.js教程之a(chǎn)xios與網(wǎng)絡(luò)傳輸?shù)膶W(xué)習(xí)實(shí)踐

    這篇文章主要給大家介紹了Vue.js之a(chǎn)xios與網(wǎng)絡(luò)傳輸?shù)南嚓P(guān)資料,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟隨小編一起來(lái)學(xué)習(xí)學(xué)習(xí)吧。
    2017-04-04
  • vue 組件間的通信之子組件向父組件傳值的方式

    vue 組件間的通信之子組件向父組件傳值的方式

    這篇文章主要介紹了vue 組件間的通信之子組件向父組件傳值的方式總結(jié),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • VUE前端導(dǎo)出文件之file-saver插件安裝使用教程

    VUE前端導(dǎo)出文件之file-saver插件安裝使用教程

    這篇文章主要給大家介紹了關(guān)于VUE前端導(dǎo)出文件之file-saver插件安裝使用的相關(guān)資料,file-saver是一個(gè)用于保存文件的JavaScript庫(kù),它提供了一種簡(jiǎn)單的方式來(lái)生成和保存文件,支持各種文件類(lèi)型,例如文本文件、圖片、PDF等,需要的朋友可以參考下
    2024-05-05
  • VUE el-tree組件左邊勾選,右邊清除交互問(wèn)題

    VUE el-tree組件左邊勾選,右邊清除交互問(wèn)題

    這篇文章主要介紹了VUE el-tree組件左邊勾選,右邊清除交互問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。
    2023-04-04
  • vue+iview 實(shí)現(xiàn)可編輯表格的示例代碼

    vue+iview 實(shí)現(xiàn)可編輯表格的示例代碼

    這篇文章主要介紹了vue+iview 實(shí)現(xiàn)可編輯表格的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-10-10
  • vue3中的:deep()深度選擇器詳解

    vue3中的:deep()深度選擇器詳解

    本文講述了"v-deep"深度選擇器被廢棄的情況,作者提醒讀者更新知識(shí)庫(kù),避免誤導(dǎo)他人,深度選擇器是HTML5的新屬性,用于實(shí)現(xiàn)組件私有化和防止樣式污染,如果想讓樣式中的一個(gè)選擇器作用得更深,可以使用深度選擇器,但現(xiàn)在,以前的寫(xiě)法已不再支持,需要調(diào)整方法
    2024-10-10
  • 使用Vue實(shí)現(xiàn)簡(jiǎn)單日歷效果

    使用Vue實(shí)現(xiàn)簡(jiǎn)單日歷效果

    這篇文章主要為大家詳細(xì)介紹了使用Vue實(shí)現(xiàn)簡(jiǎn)單日歷效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Vue循環(huán)中多個(gè)input綁定指定v-model實(shí)例

    Vue循環(huán)中多個(gè)input綁定指定v-model實(shí)例

    這篇文章主要介紹了Vue循環(huán)中多個(gè)input綁定指定v-model實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08

最新評(píng)論