【发布时间】:2012-10-23 13:02:56
【问题描述】:
我一直在尝试使用InputStream 从位于原始文件夹中的wav 文件的字节中读取缓冲区。
我想我不明白的是如何给出文件的正确位置。
R 资源中的 wav 文件是一个 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");
}
}
那么我怎样才能从原始文件夹中读取呢?
【问题讨论】:
-
请先格式化您的代码,然后再将其粘贴为问题。谢谢