vue2.0+vue-dplayer实现hls播放

开始

安装依赖

npm install vue-dplayer -S

1,编写组件HelloWorld.vue

<template>
<div class="hello">
<d-player ref="player" @play="play" :logo="logo" :lang="lang" :video="video" :contextmenu="contextmenu"></d-player>
</div>
</template> <script>
import VueDPlayer from './VueDPlayerHls';
import logoImg from '@/assets/logo.png';
export default {
name: 'HelloWorld',
data () {
return {
video: {
quality: [{
name: '240P',
url: 'https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8',
},{
name: '360P',
url: 'https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8',
},{
name: '720P',
url: 'https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8',
}],
pic: 'http://static.smartisanos.cn/pr/img/video/video_03_cc87ce5bdb.jpg',
defaultQuality: 1,
thumbnails: logoImg,
type: 'hls'
},
lang: 'zh-cn',
logo: logoImg,
autoplay: false,
player: null,
contextmenu: [
{
text: '博客园',
link: 'http://www.cnblogs.com/maqingyuan/'
},{
text: '博客园',
link: 'http://www.cnblogs.com/maqingyuan/'
},{
text: '博客园',
link: 'http://www.cnblogs.com/maqingyuan/'
}
]
}
},
components: {
'd-player': VueDPlayer
},
methods: {
play() {
// console.log('开始播放...')
}
},
mounted() {
// this.player = this.$refs.player.dp;
// console.log(this.player);
// var hls = new Hls();
// hls.loadSource('https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8');
// hls.attachMedia(this.player);
}
}
</script> <style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
.hello{
width: 750px;
margin: 0 auto 50px;
}
@media only screen and (max-width: 640px){
.hello{
width: 100%;
}
}
</style>

2,引入hls.js (在main.js引入)

window.Hls = require('hls.js');

3,自定义一个组件VueDPlayerHls.vue

<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: false
},
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: {
pic: this.video.pic,
defaultQuality: this.video.defaultQuality,
quality: [{
url: this.video.quality[0].url,
name: this.video.quality[0].name
},{
url: this.video.quality[1].url,
name: this.video.quality[1].name
},{
url: this.video.quality[2].url,
name: this.video.quality[2].name
}],
thumbnails: this.video.thumbnails,
type: this.video.type
}
})
player.on('play', () => {
this.$emit('play')
})
player.on('quality_start', () => {
this.$emit('quality_start')
player.on('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>
<style scoped> </style>

4,实现播放(如下图) :

最后

github地址:https://github.com/whiskyma/vue-dplayer

以上就是本文的全部内容,希望对大家的学习有所帮助,谢谢大家,记得点赞哦!!!

vue2.0+vue-dplayer实现hls播放的更多相关文章

  1. vue2.0 vue.set()

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. vue2.0 vue.extend()的拓展

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Vue2.0 Vue.set的使用

    原文链接: https://blog.csdn.net/qq_30455841/article/details/78666571

  4. vue1.0和vue2.0的区别(二)

    这篇我们继续之前的vue1.0和vue2.0的区别(一)继续说 四.循环 学过vue的同学应该知道vue1.0是不能添加重复数据的,否则它会报错,想让它重复添加也不是不可以,不过需要定义别的东西 而v ...

  5. VUE2.0学习总结

    摘要: 年后公司项目开始上vue2.0,自己对学习进行了总结,希望对大家有帮助! VUE2.0学习 vue介绍 vue是什么? https://vuefe.cn/guide vue也是一个数据驱动框架 ...

  6. vue 专题 vue2.0各大前端移动端ui框架组件展示

    Vue 专题 一个数据驱动的组件,为现代化的 Web 界面而生.具有可扩展的数据绑定机制,原生对象即模型,简洁明了的 API 组件化 UI 构建 多个轻量库搭配使用 请访问链接: https://ww ...

  7. Vue2.0音乐播放器

    学习了几周的vuejs,学习的过程中做了一个音乐播放器WebApp (顺便听听音乐~) ,过程中也有借鉴过别人做的,感觉受益匪浅 链接 项目在线地址 : 音乐播放器 github : https:// ...

  8. vue2.0实践 —— Node + vue 实现移动官网

    简介 使用 Node + vue 对公司的官网进行了一个简单的移动端的实现. 源码 https://github.com/wx1993/node-vue-fabaocn 效果 组件 轮播图(使用 vu ...

  9. 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十五 ║Vue基础:JS面向对象&字面量& this字

    缘起 书接上文<从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十四 ║ VUE 计划书 & 我的前后端开发简史>,昨天咱们说到了以我的经历说明的web开发经历的 ...

随机推荐

  1. golang使用ssh远程连接服务器并执行命令

    安装golang.org/x 直接去github上面,把https://github.com/zieckey/golang.org,把整个目录拷贝下来放到你的gopath下面即可.记住在gopath的 ...

  2. IBM XIV

    参考:https://www.doit.com.cn/p/author/xigua 参考:http://www.doit.com.cn/p/196056.html 图片说明: IBM XIV存储系统采 ...

  3. 【2018-01-26】SqlServer 检查死锁和阻塞

    利用sys.sysprocesses SQL进程检查是否出现死锁和阻塞 Sys.SysProcesses 系统表是一个很重要的系统视图,主要用来定位与解决Sql Server的阻塞和死锁 select ...

  4. 说一下 synchronized 底层实现原理?(未完成)

    说一下 synchronized 底层实现原理?(未完成)

  5. python_网络编程socket(UDP)

    服务端: import socket sk = socket.socket(type=socket.SOCK_DGRAM) #创建基于UDP协议的socket对象 sk.bind(('127.0.0. ...

  6. input 更改 pleaseholder 的字体样式

    /* WebKit browsers */input::-webkit-input-placeholder {    color: red;    font-size: 14px;}/* Mozill ...

  7. c语言1博客作业10

    一.本周作业头 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/SE2019-3/homework/10101 ...

  8. 快速搭建FTP服务器

    快速搭建一个本地的FTP服务器  如果需要开发FTP文件上传下载功能,那么需要在本机上搭建一个本地FTP服务器,方便调试.第一步:配置IIS Web服务器1.1 控制面板中找到“程序”并打开 1.2 ...

  9. django-rest-framework --- 基础简介

    目录 drf知识点 --- 后台 django restframework介绍 drf框架安装 接口 接口组成 如何写接口 接口组成的两大部分 接口文档 Postman接口工具使用 基于resrful ...

  10. C# Dynamic动态对象

    1.ExpandoObject dynamic expObj = new ExpandoObject(); expObj.FirstName = "Daffy"; expObj.L ...