项目中有一个视频合集,需要实现视频连续播放。实现的基本思路就是监听视频播放结束事件,然后获取当前视频索引+1,将该参数传入视频播放的方法,即可实现连续播放。
在Vue.js中的视频播放事件如下:
title="you can listen some event if you need"
@play="onPlayerPlay($event)"
@pause="onPlayerPause($event)"
@ended="onPlayerEnded($event)"
@loadeddata="onPlayerLoadeddata($event)"
@waiting="onPlayerWaiting($event)"
@playing="onPlayerPlaying($event)"
@timeupdate="onPlayerTimeupdate($event)"
@canplay="onPlayerCanplay($event)"
@canplaythrough="onPlayerCanplaythrough($event)"
title="or listen state change"
@statechanged="playerStateChanged($event)"
title="The prepared event will be triggered after the videojs program instance completes, and its callback player object is the videojs callback function in this context"
@ready="playerReadied">
使用方法:直接嵌入video-player标签即可,示例如下
<template>
<video-player ref="videoPlayer"
@ended="onPlayerEnded($event)"
</video-player>
</template>
参考资料:
vue.js 视频播放