繁体   English   中英

我将如何在节点 js 中加载 ogg 文件

[英]How would I load an ogg file in node js

我的目标是在 node.js 中加载 ogg 文件我试过 ReadFile 但遇到了这个错误:无法读取文件。 [错误:ENOENT:没有那个文件或目录,打开'Main\\game\\songs\\test\\Voices.ogg'] 并且该文件确实存在。

代码:

fs.readdir('./game/songs', function(err, files){
        if (err) {
            console.log("Could not list the directory.", err)
            return
        }
        files.forEach(function(file, index){
            fs.readFile('./game/songs/'+file+"/Inst.ogg", function(err, data){
                if (err) {
                    console.log("Could not read file.", err)
                    return
                }
            })
            fs.readFile('./game/songs/'+file+"/Voices.ogg", function(err, data){
                if (err) {
                    console.log("Could not read file.", err)
                    return
                }
            })
        })
    })

您应该传递文件的绝对路径,使用内置path模块的join()函数:

const path = require('path');
const fs = require('fs');

fs.readFile(path.join(__dirname, 'YOUR_PATH_HERE'), function(err, data) {});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM