成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

vue2.0+vue-dplayer如何實(shí)現(xiàn)hls播放

這篇文章將為大家詳細(xì)講解有關(guān)vue2.0+vue-dplayer如何實(shí)現(xiàn)hls播放,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)專(zhuān)注于白水企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站開(kāi)發(fā)。白水網(wǎng)站建設(shè)公司,為白水等地區(qū)提供建站服務(wù)。全流程按需求定制設(shè)計(jì),專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)

開(kāi)始

安裝依賴(lài)

npm install vue-dplayer -S

編寫(xiě)組件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

本來(lái)是使用import引入,可是執(zhí)行報(bào)錯(cuò)。所以就先在index.html內(nèi)用script標(biāo)簽引入進(jìn)來(lái)。

<!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頁(yè)面代碼,想支持hls,需要將video.type 設(shè)置為”hls”,但是我修改之后發(fā)現(xiàn)無(wú)法播放。于是去看了源碼,發(fā)現(xiàn)源碼內(nèi)有這樣一處:

vue2.0+vue-dplayer如何實(shí)現(xiàn)hls播放

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

修改源碼

自定義一個(gè)組件VueDPlayerHls.vue,然后copy源代碼,問(wèn)題處修改為: 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)播放

vue2.0+vue-dplayer如何實(shí)現(xiàn)hls播放

關(guān)于“vue2.0+vue-dplayer如何實(shí)現(xiàn)hls播放”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

網(wǎng)站名稱(chēng):vue2.0+vue-dplayer如何實(shí)現(xiàn)hls播放
文章地址:http://jinyejixie.com/article18/pspggp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站改版、網(wǎng)站收錄外貿(mào)建站、網(wǎng)站內(nèi)鏈品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
鄯善县| 伊宁市| 庄浪县| 吴堡县| 山阳县| 郎溪县| 洪江市| 辰溪县| 从化市| 灵宝市| 沁阳市| 二连浩特市| 凤冈县| 洪雅县| 武宣县| 四子王旗| 凤冈县| 耒阳市| 新密市| 长子县| 普陀区| 巴中市| 吉林省| 汉阴县| 思茅市| 高陵县| 双江| 博白县| 名山县| 赣榆县| 郎溪县| 大渡口区| 固安县| 泽州县| 林芝县| 阳信县| 纳雍县| 宁明县| 南郑县| 三原县| 岳西县|