我一直在尝试使用InputStream
从位于原始文件夹中的wav
文件的字节中读取缓冲区。从“原始”文件夹中的资源wav文件获取输入数据
我想我不明白的是如何给文件的正确位置。 的wav
文件在R资源是一个int,所以我不能只是做:
InputStream is = new FileInputStream(R.raw.music);
因为int
没有被确认为FileInputStream
。
基本上是我的代码是什么修改后的版本,我发现:
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");
}
}
所以,我怎样才能从原始文件夹读?
http://developer.android.com/guide/topics/resources/accessing-resources.html。通过这个链接。 – Raghunandan
在将其粘贴为问题之前,请先格式化您的代码。谢谢 –