首先,我们需要在vue工程中安装video.js相关依赖。
npm install --save video.js
npm install --save videojs-contrib-hls
引入js对象
import videojs from 'video.js/dist/video.min'
import 'video.js/dist/video-js.min.css'
import 'videojs-flash/dist/videojs-flash';
videojs-contrib-hls 用于在电脑端播放 如果只需手机播放可以不引入
<video id="my-video" class="video-js vjs-default-skin" controls preload="auto" poster="../assets/video.png">
<source src="http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/f865d8a05285890787810776469/playlist.f3.m3u8" type="application/x-mpegURL">
</video>
最后,我们在mounted节点初始化播放器:
videojs('my-video', {
bigPlayButton: false,
textTrackDisplay: false,
posterImage: true,
errorDisplay: false,
controlBar: true
}, function () {
this.play()
})
多视频列表循环播放代码
<div v-for="(item,index) in vedioData" :key="'spqymain'+index">
<video :id="'my-video'+index" class="video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" style='width: 100%;height: 100%'>
<source :src="item.path" style='width: 100%;height: 100%' type="application/x-mpegURL">
</video>
</div>
export default {
data() {
return {
vedioData: [
{
region: "烟台市蓬莱阁景区1",
path:
"http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/f865d8a05285890787810776469/playlist.f3.m3u8",
type: "application/x-mpegURL" //播放hls流
},
{
region: "烟台市蓬莱阁景区2",
path:
"http://1252093142.vod2.myqcloud.com/4704461fvodcq1252093142/f865d8a05285890787810776469/playlist.f3.m3u8",
type: "application/x-mpegURL" //播放hls流
},
]
};
},
mounted() {
//id必须是唯一的,遍历id,
for(let i=0;i<this.vedioData.length;i++){
videojs(
"my-video"+i,
{
// bigPlayButton: false,
textTrackDisplay: false,
posterImage: true,
errorDisplay: false,
controlBar: true
},
function() {
this.play();
}
);
}
},
}
转载于:(https://blog.csdn.net/xingchen678/article/details/100900846)
网友评论