还是播放不了视频,能不能换一种不用fs的遍历方式
时间: 2024-03-21 16:40:23 浏览: 52
如果不能使用 fs 模块读取本地文件夹,可以使用 Web API 中的 fetch 方法来读取本地文件夹中的视频文件。具体步骤如下:
1. 在 mounted 钩子函数中,使用 fetch 方法读取本地文件夹中的视频文件列表,将其转换为数组并保存到 videoList 中。代码如下:
```javascript
mounted() {
const video = this.$refs.videoPlayer;
// 使用 fetch 方法读取本地文件夹中的视频文件列表
fetch('./src/video/')
.then(response => response.text())
.then(data => {
// 转换为数组并保存到 videoList 中
const videoFiles = data.split('\n').filter(file => file.endsWith('.mp4'));
const videoList = videoFiles.map(file => './src/video/' + file);
this.videoList = videoList;
video.src = this.currentVideoSrc;
video.play();
this.autoplayInterval = setInterval(() => {
this.playNextVideo()
}, 5000);
});
video.addEventListener('ended', () => {
this.playNextVideo()
});
},
```
2. 修改 toggleFullScreen 方法中的 video 元素,使用 document.querySelector 方法来获取视频元素。代码如下:
```javascript
toggleFullScreen() {
const video = document.querySelector('.video-container video');
if (document.fullscreenElement) {
document.exitFullscreen()
} else {
video.requestFullscreen()
}
}
```
这样就可以不使用 fs 模块,使用 fetch 方法读取本地文件夹中的视频文件列表并播放视频了。
阅读全文
相关推荐



















