<template> <div class="video-container"> <video ref="videoPlayer" @ended="playNextVideo" @click="toggleFullScreen" controls></video> </div> </template> <script> import fs from 'fs'; export default { name: 'FullScreenVideoPlayer', data() { return { currentVideoIndex: 0, // 当前播放的视频索引 videoList: [], // 视频列表 autoplayInterval: null // 自动播放的定时器 } }, computed: { currentVideoSrc() { return this.videoList[this.currentVideoIndex] } }, mounted() { const video = this.$refs.videoPlayer; // 读取本地文件夹内的视频文件 fs.readdir('./src/video/', (err, files) => { if (err) throw err; // 过滤非视频文件 const videoFiles = files.filter(file => file.endsWith('.mp4')) // 将视频文件的路径存入 videoList 数组中 this.videoList = videoFiles.map(file => './src/video/' + file) // 自动播放 video.src = this.currentVideoSrc; video.play(); this.autoplayInterval = setInterval(() => { this.playNextVideo() }, 5000); }); video.addEventListener('ended', () => { this.playNextVideo() }); }, beforeUnmounted() { // 清除定时器 clearInterval(this.autoplayInterval) }, methods: { playNextVideo() { const video = this.$refs.videoPlayer; this.currentVideoIndex++; if (this.currentVideoIndex >= this.videoList.length) { this.currentVideoIndex = 0 } video.src = this.currentVideoSrc; video.play() }, toggleFullScreen() { const video = this.$refs.videoPlayer; if (document.fullscreenElement) { document.exitFullscreen() } else { video.requestFullscreen() } } } } </script> <style scoped> .video-container { width: 100%; height: 100%; } video { width: 100%; height: 100%; object-fit: contain; } </style>这里面视频播放的路径修改要在哪里改
时间: 2024-03-20 18:45:20 浏览: 149
TUP第8期HTML5黄后锦演讲PPT
5星 · 资源好评率100%
视频播放的路径在这段代码中进行修改:
```
// 将视频文件的路径存入 videoList 数组中
this.videoList = videoFiles.map(file => './src/video/' + file)
```
这里将视频文件的路径存入了 videoList 数组中,并且在路径前加上了 `./src/video/`。如果你想要修改视频文件夹的路径,只需要修改这个字符串即可。如果你想要修改视频文件的后缀名,只需要修改 `file.endsWith('.mp4')` 中的 `mp4` 即可。
阅读全文