wav
を使用して、rawフォルダーにあるファイルのバイトからバッファーを読み取ろうとしていますInputStream
。
私が理解していないのは、ファイルの正しい場所を指定する方法だと思います。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");
}
}
では、rawフォルダーからどのように読み取ることができますか?