
10年积累的网站设计、网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有振兴免费网站建设让你可以放心的选择与我们合作。
屏幕快照 2019-04-01 下午8.06.02.png
方法一:iframe插入视频链接
1.1 ##### 当前播放的视频
{{this.activeVideo.title}}
1.2#####视频列表
{{video.title}}
{{video.speaker}} {{video.views}} Views{{video.describe}}
1.3#####定义的数据结构(自己写的demo,可能实际中后台返的数据结构会有所不同)
data () {
return {
flag:false,
videos:[{
id:1,title:'test2',youtobeURL:'http://player.youku.com/embed/XMzcwNTY3NTM2MA',speaker:'harry', likes:101,views:0,describe:'good'
},{
id:2,title:'test3',youtobeURL:'http://player.youku.com/embed/XMzcwNTY3NTM2MA',speaker:'harry', likes:100,views:75,describe:'good'
}],
activeVideo:{
id:3,title:'test1',thumbnail:'./../../static/images/headImg.png',speaker:'harry', likes:0,views:0,describe:'good',
youtobeURL:'http://player.youku.com/embed/XMzcwNTY3NTM2MA'
}
}
}1.4##### 点击视频列表中的视频转变为当前视频
ps:最开始的时候把点击事件写在iframe上,但是点击无效。后来写了个div,完美解决:
1.5#####转换当前视频的点击事件:通过id来判断当前点击的是哪个
activeVideoShow(id){
this.videos.filter(item=>{
if(id == item.id){
this.activeVideo=item
}
})
}方法二:引用了vue-video-player插件(没有视频列表)
相对于iframe方法写了一堆div和style,vue-video-player简直精简到起飞
2.1#####第一次用这个插件,不是很熟悉,所以根据官方的API 写了一个videoPlayer的组件,代码如下:
2.1-1#####需要引入video.js和定义相关的options
import videojs from 'video.js'
---------------------------------
props:{
options:{
type:Object,
default(){
return{
}
}
}
},
data(){
return{
player:null
}
},
mounted(){
this.player=videojs(this.$refs.videoPlayer,this.options,function onPlayerReady(){
console.log('onPlayerReady',this)
})
}2.2#####在插入视频的页面中引入上面的videoPlayer组件,在view层代码如下:
2.3#####需要引入的插件
import './../../node_modules/video.js/dist/video-js.css'
import './../../node_modules/vue-video-player/src/custom-theme.css'
import videojs from 'video.js'
import {videoPlayer} from 'vue-video-player'
import 'videojs-flash'
import VideoPlayer from '@/components/videoPlayer.vue'2.3-1#####定义相关数据
props:{
state:Boolean,
},
data(){
return{
videoOptions:{
playbackRates:[1.0,1.5,2.0], // 播放速度
autoplay:false, // 如果true,浏览器准备好时开始回放
controls:true,
muted:false, // 默认情况下将会消除任何音频
loop:false, //循环播放
preload:'auto', // 代码地址: https://github.com/yinglichen/videoPlayer
ps:用canvas写了个字幕功能,还有待修缮,后期补上。
总结
以上所述是小编给大家介绍的基于Vue插入视频的2种方法小结,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对创新互联网站的支持!
分享文章:基于Vue插入视频的2种方法小结
链接地址:http://www.jxjierui.cn/article/jhjdgs.html


咨询
建站咨询
