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

vue2.0+vue-dplayer實現(xiàn)hls播放的示例

 更新時間:2018年03月02日 10:23:16   作者:Fei___  
這篇文章主要介紹了vue2.0+vue-dplayer實現(xiàn)hls播放的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

起因

之前寫了一篇《 vue2.0+vue-video-player實現(xiàn)hls播放》,里邊有提到在用vue-video-player之前,我嘗試著使用vue-dplayer實現(xiàn)hls播放,但是當時時間緊迫,還沒有完成,就換方案了?,F(xiàn)在抽時間把它補齊吧。

開始

安裝依賴

npm install vue-dplayer -S

編寫組件HelloWorld.vue

<template>
 <div class="hello">
  <d-player ref="player" @play="play" :video="video" :contextmenu="contextmenu"></d-player>
 </div>
</template>

<script>
import VueDPlayer from './VueDPlayerHls';
export default {
 name: 'HelloWorld',
 data () {
  return {
   msg: 'Welcome to Your Vue.js App',
   video: {
     url: 'https://logos-channel.scaleengine.net/logos-channel/live/biblescreen-ad-free/chunklist_w630020335.m3u8',
     pic: 'http://static.smartisanos.cn/pr/img/video/video_03_cc87ce5bdb.jpg',
     type: 'hls'
    },
    autoplay: false,
    player: null,
    contextmenu: [
      {
        text: 'GitHub',
        link: 'https://github.com/MoePlayer/vue-dplayer'
      }
    ]
  }
 },
 components: {
  'd-player': VueDPlayer
 },
 methods: {
  play() {
    console.log('play callback')
   }
 },
 mounted() {
  this.player = this.$refs.player.dp;
  // console.log(this.player);
  var hls = new Hls();
  hls.loadSource('https://logos-channel.scaleengine.net/logos-channel/live/biblescreen-ad-free/chunklist_w630020335.m3u8');
  hls.attachMedia(this.player);
 }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

引入hls.js

本來是使用import引入,可是執(zhí)行報錯。所以就先在index.html內(nèi)用script標簽引入進來。

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <title>vue-dplayer-hls</title>
 </head>
 <body>
  <div id="app"></div>
  <!-- built files will be auto injected -->
  <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
 </body>
</html>

注意:

根據(jù)DPlayer Demo頁面代碼,想支持hls,需要將video.type 設(shè)置為”hls”,但是我修改之后發(fā)現(xiàn)無法播放。于是去看了源碼,發(fā)現(xiàn)源碼內(nèi)有這樣一處:

這里寫圖片描述

也就是說不論你在自己的組件內(nèi)填寫的是什么,其實都是使用的'normal'來new的Dplayer實例。

修改源碼

自定義一個組件VueDPlayerHls.vue,然后copy源代碼,問題處修改為: type: this.video.type

<template>
 <div class="dplayer"></div>
</template>

<script>
 require('../../node_modules/dplayer/dist/DPlayer.min.css');
 import DPlayer from 'DPlayer'
 export default {
  props: {
   autoplay: {
    type: Boolean,
    default: false
   },
   theme: {
    type: String,
    default: '#FADFA3'
   },
   loop: {
    type: Boolean,
    default: true
   },
   lang: {
    type: String,
    default: 'zh'
   },
   screenshot: {
    type: Boolean,
    default: false
   },
   hotkey: {
    type: Boolean,
    default: true
   },
   preload: {
    type: String,
    default: 'auto'
   },
   contextmenu: {
    type: Array
   },
   logo: {
    type: String
   },
   video: {
    type: Object,
    required: true,
    validator(value) {
     return typeof value.url === 'string'
    }
   }
  },
  data() {
   return {
    dp: null
   }
  },
  mounted() {
   const player = this.dp = new DPlayer({
    element: this.$el,
    autoplay: this.autoplay,
    theme: this.theme,
    loop: this.loop,
    lang: this.lang,
    screenshot: this.screenshot,
    hotkey: this.hotkey,
    preload: this.preload,
    contextmenu: this.contextmenu,
    logo: this.logo,
    video: {
     url: this.video.url,
     pic: this.video.pic,
     type: this.video.type
    }
   })
   player.on('play', () => {
    this.$emit('play')
   })
   player.on('pause', () => {
    this.$emit('pause')
   })
   player.on('canplay', () => {
    this.$emit('canplay')
   })
   player.on('playing', () => {
    this.$emit('playing')
   })
   player.on('ended', () => {
    this.$emit('ended')
   })
   player.on('error', () => {
    this.$emit('error')
   })
  }
 }
</script> 

在原組件(HelloWorld.vue)內(nèi)import新組件

import VueDPlayer from './VueDPlayerHls';

實現(xiàn)播放

這里寫圖片描述

最后

github地址:https://github.com/PhillCheng/vue-dplayer-hls

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue.js中methods watch和computed的區(qū)別示例詳解

    vue.js中methods watch和computed的區(qū)別示例詳解

    methods,watch和computed都是以函數(shù)為基礎(chǔ)的,但各自卻都不同,這篇文章主要給大家介紹了關(guān)于vue.js中methods watch和computed區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • 前端主流框架vue學習筆記第一篇

    前端主流框架vue學習筆記第一篇

    一步一步學Vue,這篇文章為大家分享了第一篇前端主流框架vue學習筆記,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • 使用vite項目打包資源分配目錄

    使用vite項目打包資源分配目錄

    這篇文章主要介紹了使用vite項目打包資源分配目錄方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • vue3使用Electron打包成exe的方法與打包報錯解決

    vue3使用Electron打包成exe的方法與打包報錯解決

    在前端開發(fā)中,Electron是一種常用的工具,它允許開發(fā)者使用Web技術(shù)構(gòu)建桌面應用程序,本文主要介紹了vue3使用Electron打包成exe的方法與打包報錯解決,具有一定的參考價值,感興趣的可以了解一下
    2024-06-06
  • Vue3?如何通過虛擬DOM更新頁面詳解

    Vue3?如何通過虛擬DOM更新頁面詳解

    這篇文章主要為大家介紹了Vue3?如何通過虛擬DOM更新頁面詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09
  • Vuex數(shù)據(jù)持久化實現(xiàn)的思路與代碼

    Vuex數(shù)據(jù)持久化實現(xiàn)的思路與代碼

    Vuex數(shù)據(jù)持久化可以很好的解決全局狀態(tài)管理,當刷新后數(shù)據(jù)會消失,這是我們不愿意看到的。這篇文章主要給大家介紹了關(guān)于Vuex數(shù)據(jù)持久化實現(xiàn)的思路與代碼,需要的朋友可以參考下
    2021-05-05
  • vue中v-model失效原因以及解決方案

    vue中v-model失效原因以及解決方案

    這篇文章主要給大家介紹了關(guān)于vue中v-model失效原因以及解決方案的相關(guān)資料,vue的v-model是一個雙向綁定的數(shù)據(jù)流,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-07-07
  • vue+element+Java實現(xiàn)批量刪除功能

    vue+element+Java實現(xiàn)批量刪除功能

    這篇文章主要介紹了vue+element+Java實現(xiàn)批量刪除功能,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-04
  • 詳解vscode中vue代碼顏色插件

    詳解vscode中vue代碼顏色插件

    vscode的確是前端開發(fā)中很好的工具,安裝顏色插件,從視覺上是美的享受。這篇文章主要介紹了vscode中vue代碼顏色插件 ,需要的朋友可以參考下
    2018-10-10
  • Vue項目總結(jié)之webpack常規(guī)打包優(yōu)化方案

    Vue項目總結(jié)之webpack常規(guī)打包優(yōu)化方案

    這篇文章主要介紹了vue項目總結(jié)之webpack常規(guī)打包優(yōu)化方案,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06

最新評論