videojs
loadCss () {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.charset = 'utf-8'
link.href = 'https://cdn.bootcss.com/video.js/6.3.3/video-js.min.css'
document.head.appendChild(link)
}
import videojs from 'video.js'
initVideo (src) {
var video = document.createElement('video')
video.id = 'video'
video.style = 'width: 100%;height: 100%;'
video.controls = true
video.setAttribute('playsinline', true)
video.setAttribute('x5-video-player-type', 'h5')
video.setAttribute('webkit-playsinline', true)
var source = document.createElement('source')
source.src = src
source.type = 'application/x-mpegURL'
video.appendChild(source)
const videoBox = document.getElementById('zlz')
videoBox.appendChild(video)
const that = this
that.player = videojs(video, {
src: that.detailData.liveUrl,
type: 'application/x-mpegURL',
title: '12334567788999900',
playbackRates: [0.7, 1.0, 1.5, 2.0],
autoDisable: true,
preload: 'auto',
language: 'zh-CN',
fluid: true,
muted: false,
aspectRatio: '16:9',
controls: true,
autoplay: false,
loop: false,
screenshot: true,
controlBar: {
volumePanel: {
inline: false
},
timeDivider: true,
durationDisplay: true,
progressControl: true,
remainingTimeDisplay: true,
fullscreenToggle: true,
pictureInPictureToggle: true
}
}, function () {
this.on('error', function () {
console.log('请求数据时遇到错误')
})
this.on('stalled', function () {
console.log('网速失速')
})
this.on('play', function () {
console.log('开始播放')
})
this.on('pause', function () {
console.log('暂停')
})
this.on('timeupdate', function () {
})
})
},
ps://兼容新教差
腾讯TcPlayer
在app.vue引入
const script1 = document.createElement('script')
script1.charset = 'utf-8'
script1.src = 'https://imgcache.qq.com/open/qcloud/video/vcplayer/TcPlayer-2.3.1.js'
document.head.appendChild(script1)
<div class="video" id="player-container-id"></div>
initVideo1 (src, coverImage) {
this.player = new TcPlayer('player-container-id', {
m3u8: src,
autoplay: false,
poster: { style: 'default', src: coverImage },
width: '100%',
height: '100%',
live: true,
controlBar: {
playToggle: false
},
listener: function(msg){
console.log(msg)
if (msg.type === 'error') {
let errorMsg = ''
switch (msg.detail.code) {
case 2:
errorMsg = '无法加载视频文件,请检查网络,以及视频文件是否允许跨域请求访问,m3u8文件是否存在'
break
default:
errorMsg = '直播加载失败'
break
}
uni.showToast({
title: errorMsg,
icon: 'none',
duration: 2000
})
}
}
})
},