1.npm install vue-video-player -S
2.全局引用
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
Vue.use(VideoPlayer)
2.局部引用
import {
videoPlayer
} from 'vue-video-player'
import 'video.js/dist/video-js.css'
export default {
components: {
videoPlayer
}
}
3.html
<video-player class="video-player vjs-custom-skin"
ref="videoPlayer"
:playsinline="true"
:options="playerOptions">
</video-player>
4.methods 获取播放时间
this.$nextTick(() => {
setTimeout(() => {
let du = document.getElementById("vjs_video_3_html5_api") //获取组件下的video
var hour = parseInt((du.duration) / 3600);
var minute = parseInt((du.duration % 3600) / 60);
var second = parseInt(du.duration % 60);
let result = ''
if (hour > 0) {
result = this.formatTimeStr(hour) + ':' + this.formatTimeStr(minute) + ':' + this
.formatTimeStr(second)
} else {
result = this.formatTimeStr(minute) + ':' +
this.formatTimeStr(second)
}
return result //转化成分,秒
}, 200)
})
formatTimeStr(val) {
if (val > 9) {
return val
} else {
return '0' + val
}
},
vue-video-player获取播放时间
最新推荐文章于 2024-04-29 21:35:15 发布