@前端vue-video-player 插件多视频获取后端数据的插件实践总结
npm install
npm install vue-video-player -S;
提醒:一定要用npm ,一定要用npm 不要用cnpm 会报错!!!
否则会报“The “flash” tech is undefined. Skipped browser support check for that tech”
main.js
直接贴到main.js 里面就可以了。
import VideoPlayer from ‘vue-video-player’
import ‘vue-video-player/src/custom-theme.css’
import ‘video.js/dist/video-js.css’
Vue.use(VideoPlayer)
html 部分
<div
class='demo'
v-for="(item,index) in reply"
:key="index"
>
<video-player
class="video-player vjs-custom-skin"
ref="videoPlayer"
:playsinline="true"
:options="playerOptions[index]"
@play="onPlayerPlay($event)"
@pause="onPlayerPause($event)"
@ended="onPlayerEnded($event)"
@loadeddata="onPlayerLoadeddata($event)"
@timeupdate="onPlayerTimeupdate($event)"
@ready="playerReadied($event)" >
</video-player>
</div>
data 部分
我还没有获取后台数据,所以手写了假数据;
playerOptions–video-player–配置一些常用参数;
reply: ----获取后台返回的数据;
js 部分
其他按钮方法
// 播放回调
onPlayerPlay(player) {
console.log(“player play!”, player);
},
// 暂停回调
onPlayerPause(player) {
console.log("player pause!", player);
},
// 视频播完回调
onPlayerEnded($event) {
console.log(player);
},
// DOM元素上的readyState更改导致播放停止
onPlayerWaiting($event) {
console.log(player);
},
// 已开始播放回调
onPlayerPlaying($event) {
console.log(player);
},
// 当播放器在当前播放位置下载数据时触发
onPlayerLoadeddata($event) {
console.log(player);
},
// 当前播放位置发生变化时触发。
onPlayerTimeupdate($event) {
console.log(player);
},
实现效果: