我一直在尝试使用 InputStream
从原始文件夹中的 wav
文件的字节中读取缓冲区。
我认为我不明白的是如何给出文件的正确位置。
R 资源中的 wav
文件是一个 int,所以我不能这样做:
InputStream is = new FileInputStream(R.raw.music);
因为 FileInputStream
未确认 int
。
基本上我的代码是我发现的东西的修改版本:
public void read(short[] musicin) {
try {
// Create a DataInputStream to read the audio data back from the saved file.
InputStream is = new FileInputStream("R.raw.music");
BufferedInputStream bis = new BufferedInputStream(is);
DataInputStream dis = new DataInputStream(bis);
int buffsize=512;
// Read the file into the music array.
int i = 0;
while (i<buffsize&&dis.available() > 0) {
musicin[i] = dis.readByte();
i++;
}
// Close the input streams.
dis.close();
} catch (Throwable t) {
Log.e("AudioTrack","Playback Failed");
}
}
那么如何从 raw 文件夹中读取内容呢?
最佳答案
在您的 Activity 类(class)中
Context c;
c=this;
new yourClass(c);
在你的类(class)
public yourclass(Context context)
{
InputStream in = context.getResources().openRawResource(R.raw.yourfilename);
}
关于java - 从 "raw"文件夹中的资源 wav 文件获取输入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13031033/