前几天做视频管理器,原计划使用vue-video-player 库来播放视频,但是发现这个库播放视频,好像需要自己手动截封面【ps: 没有仔细研究vue-video-player,如果这里有不对的地方,请告诉小弟……】
由于不想再多引一个库,索性用video 试了一下,惊奇的发现 默认就有封面:
以下是 .vue 文件:
<template>
<video class="video-style"
controls
autoplay
:src="file.url"
:ref="dialogVideo"
style="width: 268px; height: 170px"
></video>
</template>
<script>
export default {
data () {
return {
// 视频url地址
file: {
url: 'http://……'
}
}
}
}
</script>
<style lang="scss" scoped>
.video-style {
background: #303643;
border-radius: 8px;
margin: 4px;
}
</style>
也可以使用 dialogVideo 来控制播放状态:
if (this.$refs.dialogVideo.paused) {
this.$refs.dialogVideo.play();
} else {
this.$refs.dialogVideo.pause();
}