我想知道如何将字节数组转换为音频文件, 我以字节格式发送音频文件 但我希望它在收到
后转换为音频文件以下是我的代码: -
//Method to convert file to byteArray
public static byte[] convertStreamToByteArray(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[10240];
int i = Integer.MAX_VALUE;
while ((i = is.read(buff, 0, buff.length)) > 0) {
baos.write(buff, 0, i);
}
return baos.toByteArray(); // be sure to close InputStream in calling function
}
//on click of send button
mSendButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Send a message using content of the edit text widget
TextView view = (TextView) findViewById(R.id.edit_text_out);
// String message = view.getText().toString();
InputStream inStream = getResources().openRawResource(R.raw.hany);
byte[] message = null;
try {
message = convertStreamToByteArray(inStream);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sendMessage(message);
}
});