简体   繁体   English

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

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

My goal is to load ogg files in node.js I've tried ReadFile but hits me up with this error: Could not read file.我的目标是在 node.js 中加载 ogg 文件我试过 ReadFile 但遇到了这个错误:无法读取文件。 [Error: ENOENT: no such file or directory, open 'Main\\game\\songs\\test\\Voices.ogg'] and the file does exist. [错误:ENOENT:没有那个文件或目录,打开'Main\\game\\songs\\test\\Voices.ogg'] 并且该文件确实存在。

Code:代码:

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
                }
            })
        })
    })

You should pass the absolute path of the file, use the built-in path module's join() function:您应该传递文件的绝对路径,使用内置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