我从wav for android studio
中读取了许多用于读取字节的代码但我仍然无法从wav获取字节
真的需要代码或演示,所以我可以得到我需要的东西
我的代码有什么问题
Resources inn = getResources();
InputStream in = inn.openRawResource(R.raw.ccheer);
BufferedInputStream bis = new BufferedInputStream(in, 8000);
DataInputStream dis = new DataInputStream(bis);
byte[] music = null;
music = new byte[1024];
int i = 0;
try {
while (dis.available() > 0) {
music[i]=dis.readByte();
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
这是我的新代码。仍然无法读取字节[]
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_AUDIO_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
System.out.println("Uri: " + uri);
InputStream is = new FileInputStream(getRealPathFromURI(this,uri));
}
}
public static byte[] convertStreamToByteArray(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte buffer[] = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) != -1) {
baos.write(buffer, 0, length);
}
return baos.toByteArray();
}
怎么了?只想读这样或其他方式......
字节00
字节11
字节22 ...