vue组件播放m3u8格式视频
1.下载依赖npm install vue-video-player videojs-contrib-hls --save2.直接上例子<template><div class="liveView"><video-playerclass="vjs-custom-skin"ref="videoPlayer":options="playerOptions"@ready="
·
1.下载依赖
npm install vue-video-player videojs-contrib-hls --save
2.直接上例子
<template>
<div class="liveView">
<video-player class="vjs-custom-skin"
ref="videoPlayer"
:options="playerOptions"
@ready="onPlayerReadied"
@timeupdate="onTimeupdate"
:playsinline="playsinline">
</video-player>
</div>
</template>
<script>
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'
import 'videojs-contrib-hls'
export default {
name: 'live',
components: {
videoPlayer
},
data () {
return {
initialized: false,
currentTech: '',
streams: {
rtmp: '',
hls: ''
},
playerOptions: {
overNative: true,
autoplay: false,
controls: true,
techOrder: ['html5'],
sourceOrder: true,
flash: {
hls: { withCredentials: false }
},
html5: { hls: { withCredentials: false } },
sources: [
{
withCredentials: false,
type: 'application/x-mpegURL',
src: 'https://cdn.letv-cdn.com/2018/12/05/JOCeEEUuoteFrjCg/playlist.m3u8'
}
]
}
}
},
computed: {
player () {
return this.$refs.videoPlayer.player
},
currentStream () {
return this.currentTech === 'Flash' ? 'RTMP' : 'HLS'
},
playsinline () {
let ua = navigator.userAgent.toLocaleLowerCase()
// x5内核
if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
return false
} else {
// ios端
return true
}
}
},
methods: {
onPlayerReadied () {
if (!this.initialized) {
this.initialized = true
this.currentTech = this.player.techName_
}
},
// record current time
onTimeupdate (e) {
console.log('currentTime', e.cache_.currentTime)
},
}
}
</script>
<style scoped>
.liveView {
position: relative;
}
</style>
更多推荐
已为社区贡献71条内容
所有评论(0)