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. zabbix-通过自动注册自动添加主机

    自动注册和自动发现可以实现一样的效果,就是自动添加符合条件的主机到监控,那跟自动发现有什么区别? 其实自动发现是由弊端的,上文也说到了,zabbix server是主动去扫描网段,寻找agent的,试 ...

  2. trape 一种识别工具

    trape是一种识别工具,可以让你跟踪任何人,你可以得到的信息非常详细.通过去识别现有的网站所登录的用户,来追踪一个人的虚拟身份 如何使用它首先卸载工具.git clone https://githu ...

  3. jquery 选择器能否查找display:none的元素

    jQuery可以用可见性“:hidden”查找“display:none”的元素. 1.新家html文档,在head标签中引入本地jQuery文件,也可以引入cdn文件: 2.在body标签中添加一些 ...

  4. 使用 webpack-bundle-analyzer 分析 webpack 代码库拆分块

    github:https://github.com/webpack-contrib/webpack-bundle-analyzer 1.安装: cnpm install webpack-bundle- ...

  5. MySQL之text字段

    TEXT类型一般分为 TINYTEXT(255长度).TEXT(65535). MEDIUMTEXT(int最大值16M),和LONGTEXT(long最大值4G)这四种,它被用来存储非二进制字符集, ...

  6. node.js的iconv模块----在linux上读取windows编码文件

    有时候我们在windows上会保存一些中文文字信息文件,然而由于编码集的差异,这文件在linux上显示为乱码,其中一种解决方法是node.js的iconv模块 var fs = require('fs ...

  7. Ubuntu Linux虚拟机与windows快速创建共享文件夹

    有时候我们需要在windows下与远程Linux服务器传输文件,之前使用pscp传输文件很方便,但不方便传输多文件,同时也不便于查看.看了网上的教程总结创建共享文件夹的流程: 1.首先在本地windo ...

  8. .Net Core 过滤器

    请求: public class MyRequest { [Required(ErrorMessage = "Name参数不能为空")]//Required 验证这个参数不能为空 ...

  9. tarjan等

    有向图注意v在栈中时,才用dfn更新low.无向图不用判断这个. SCC和边双,都是在返回时判断low==dfn. 点双就是找割点,low(v)>=dfn(u)时,把tarjan(v)过程中放入 ...

  10. HR# 5题解

    T1 我傻了 前20个数暴力开桶记录,后面的每次暴力统计. #include<bits/stdc++.h> #define R register int using namespace s ...