最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

起因

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

開始

安裝依賴

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í)行報(bào)錯。所以就先在index.html內(nèi)用script標(biāo)簽引入進(jìn)來。

<!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)填寫的是什么,其實(shí)都是使用的'normal'來new的Dplayer實(shí)例。

修改源碼

自定義一個組件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';

實(shí)現(xiàn)播放

這里寫圖片描述

最后

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

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

相關(guān)文章

  • rollup打包vue組件并發(fā)布到npm的方法

    rollup打包vue組件并發(fā)布到npm的方法

    這篇文章主要介紹了rollup打包vue組件并發(fā)布到npm,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-05-05
  • 詳解Vue.js 響應(yīng)接口

    詳解Vue.js 響應(yīng)接口

    這篇文章主要介紹了Vue.js 響應(yīng)接口的相關(guān)資料,文中實(shí)例代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • Vue項(xiàng)目部署的實(shí)現(xiàn)(阿里云+Nginx代理+PM2)

    Vue項(xiàng)目部署的實(shí)現(xiàn)(阿里云+Nginx代理+PM2)

    這篇文章主要介紹了Vue項(xiàng)目部署的實(shí)現(xiàn)(阿里云+Nginx代理+PM2),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • vue項(xiàng)目引入antDesignUI組件實(shí)現(xiàn)

    vue項(xiàng)目引入antDesignUI組件實(shí)現(xiàn)

    本文介紹了如何以Vue引入antDesignUI,主要包括下載安裝、配置和引入組件等步驟,通過本文,讀者可以快速了解antDesignUI在Vue中的應(yīng)用,感興趣的可以了解一下
    2023-08-08
  • Vue3中使用styled-components的實(shí)現(xiàn)

    Vue3中使用styled-components的實(shí)現(xiàn)

    本文主要介紹了Vue3中使用styled-components的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-05-05
  • vue滾動tab跟隨切換效果

    vue滾動tab跟隨切換效果

    這篇文章主要為大家詳細(xì)介紹了vue滾動tab跟隨切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • vue組件中使用props傳遞數(shù)據(jù)的實(shí)例詳解

    vue組件中使用props傳遞數(shù)據(jù)的實(shí)例詳解

    這篇文章主要介紹了vue組件中使用props傳遞數(shù)據(jù)的實(shí)例詳解,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2018-04-04
  • Vue.js實(shí)現(xiàn)數(shù)據(jù)雙向綁定的代碼示例

    Vue.js實(shí)現(xiàn)數(shù)據(jù)雙向綁定的代碼示例

    在我們使用vue的時候,當(dāng)數(shù)據(jù)發(fā)生了改變,界面也會跟著更新,但這并不是理所當(dāng)然的,我們修改數(shù)據(jù)的時候vue是如何監(jiān)聽數(shù)據(jù)的改變以及當(dāng)數(shù)據(jù)發(fā)生改變的時候vue如何讓界面刷新的,所以本文就給大家講講Vue.js 數(shù)據(jù)雙向綁定是如何實(shí)現(xiàn)的
    2023-07-07
  • vue 項(xiàng)目接口管理的實(shí)現(xiàn)

    vue 項(xiàng)目接口管理的實(shí)現(xiàn)

    在vue開發(fā)中,會涉及到很多接口的處理,當(dāng)項(xiàng)目足夠大時,就需要定義規(guī)范統(tǒng)一的接口,本文就來介紹一下vue 項(xiàng)目接口管理,具有一定的參考價值,感興趣的小伙伴可以一起來了解一下
    2019-01-01
  • Vue 刷新當(dāng)前路由的實(shí)現(xiàn)代碼

    Vue 刷新當(dāng)前路由的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Vue 刷新當(dāng)前路由的實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評論

白朗县| 城市| 高密市| 武夷山市| 敖汉旗| 洪湖市| 沐川县| 科技| 南昌市| 即墨市| 平利县| 台州市| 田阳县| 育儿| 峨山| 奉贤区| 阿城市| 南平市| 普定县| 阿荣旗| 深泽县| 皮山县| 民丰县| 镇巴县| 阆中市| 南陵县| 泰安市| 扬州市| 呼和浩特市| 子长县| 楚雄市| 吴旗县| 土默特右旗| 隆子县| 十堰市| 忻州市| 开远市| 扎赉特旗| 威宁| 明溪县| 布拖县|