vue2.0+vue-dplayer实现hls播放
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播放的更多相关文章
- vue2.0 vue.set()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue2.0 vue.extend()的拓展
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Vue2.0 Vue.set的使用
原文链接: https://blog.csdn.net/qq_30455841/article/details/78666571
- vue1.0和vue2.0的区别(二)
这篇我们继续之前的vue1.0和vue2.0的区别(一)继续说 四.循环 学过vue的同学应该知道vue1.0是不能添加重复数据的,否则它会报错,想让它重复添加也不是不可以,不过需要定义别的东西 而v ...
- VUE2.0学习总结
摘要: 年后公司项目开始上vue2.0,自己对学习进行了总结,希望对大家有帮助! VUE2.0学习 vue介绍 vue是什么? https://vuefe.cn/guide vue也是一个数据驱动框架 ...
- vue 专题 vue2.0各大前端移动端ui框架组件展示
Vue 专题 一个数据驱动的组件,为现代化的 Web 界面而生.具有可扩展的数据绑定机制,原生对象即模型,简洁明了的 API 组件化 UI 构建 多个轻量库搭配使用 请访问链接: https://ww ...
- Vue2.0音乐播放器
学习了几周的vuejs,学习的过程中做了一个音乐播放器WebApp (顺便听听音乐~) ,过程中也有借鉴过别人做的,感觉受益匪浅 链接 项目在线地址 : 音乐播放器 github : https:// ...
- vue2.0实践 —— Node + vue 实现移动官网
简介 使用 Node + vue 对公司的官网进行了一个简单的移动端的实现. 源码 https://github.com/wx1993/node-vue-fabaocn 效果 组件 轮播图(使用 vu ...
- 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十五 ║Vue基础:JS面向对象&字面量& this字
缘起 书接上文<从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十四 ║ VUE 计划书 & 我的前后端开发简史>,昨天咱们说到了以我的经历说明的web开发经历的 ...
随机推荐
- MyBatis工厂工具类 MyBatisUtils
import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apach ...
- Python 中文文件统计词频 + 中文词云
1. 词频统计: import jieba txt = open("threekingdoms3.txt", "r", encoding='utf-8').re ...
- vue嵌套数据多层级里面的数据不自动更新渲染dom
可以尝试手动调用更新 主要代码: vm.$forceUpdate() 官网
- EtherNet/IP 协议应用层使用CIP协议&CIP协议中使用的TLS和DTLS(Network Infrastructure for EtherNet/IPTM: Introduction and Considerations)
- gdb无法单步调试
使用gdb调试单步程序时如果打印提示“single stepping until exit from function xxx,which has no line number information ...
- 【转】5种网络IO模型
5种网络IO模型(有图,很清楚) IO多路复用—由Redis的IO多路复用yinch Linux中对文件描述符的操作(FD_ZERO.FD_SET.FD_CLR.FD_ISSET
- sqlserver 拼接字符串
SELECT CAST(USER_ID AS VARCHAR) + ',' FROM dbo.AUTH_USER FOR XML PATH('');
- ubuntu---解决pip安装tf很慢的问题
ubuntu---解决pip安装tf很慢的问题 [问题] 执行 u@u160406:~$ sudo pip3 install tensorflow-gpu==1.15.0rc2 下载速度真的很慢 Lo ...
- Ubuntu系统---安装“搜狗拼音法”导致桌面打不开
Ubuntu系统---安装“搜狗拼音法”导致桌面打不开 ubuntu系统中文版,安装完后,自带中文输入法.中文用着好好的,用一段时间后,就会莫名的出现,切换不过来,中文输入不好用了.只是简单想装一个搜 ...
- Stepwise regression 学习笔记
之前在 SPSS 中的回归分析算法中发现,在它里面实现的算法有 Enter 和 Stepwise 两种.Enter 很容易理解,就是将所有选定的自变量一起放入模型中,直接去计算包含所有自变量的整个模型 ...