Lesen einer Ressource sound-Datei in ein Byte-array

Habe ich cheerapp.wav oder cheerapp.mp3 oder ein anderes format.

InputStream in = context.getResources().openRawResource(R.raw.cheerapp);       
BufferedInputStream bis = new BufferedInputStream(in, 8000);
//Create a DataInputStream to read the audio data from the saved file
DataInputStream dis = new DataInputStream(bis);

byte[] music = null;
music = new byte[??];
int i = 0; //Read the file into the "music" array
while (dis.available() > 0) {
    //dis.read(music[i]); //This assignment does not reverse the order
    music[i]=dis.readByte();
    i++;
}

dis.close();          

Für die music byte-array, das die Daten aus der DataInputStream. Ich weiß nicht, was die Länge, die Sie reservieren müssen.

Dies ist eine raw-Datei aus der Ressource nicht um eine Datei, daher würde ich nicht wissen, wie groß das Ding.

Prüfen mit Apache-Commons.

InformationsquelleAutor jason white | 2013-02-26

Schreibe einen Kommentar