代码:
AssetManager am = ctx.getAssets();
try {
InputStream is = am.open("kalimba.mp3"); // use recorded file instead of getting file from assets folder.
int length = is.available();
Log.v("Length", ""+length);
audio_data = new byte[length];
int bytesRead=0;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while (bytesRead != length)
{
Log.v("BytesRead", ""+bytesRead);
Log.v("Audio Data", ""+audio_data);
output.write(audio_data,bytesRead,length-bytesRead);
}
inarry = output.toByteArray();
日志猫:
10-22 07:40:11.516: E/AndroidRuntime(3369): java.lang.OutOfMemoryError
10-22 07:40:11.516: E/AndroidRuntime(3369): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
10-22 07:40:11.516: E/AndroidRuntime(3369): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
10-22 07:40:11.516: E/AndroidRuntime(3369): at com.deepak.encydep.MainActivity.getAudioFile(MainActivity.java:149) ----> Error Line
10-22 07:40:11.516: E/AndroidRuntime(3369): at com.deepak.encydep.MainActivity$1.onClick(MainActivity.java:56)
10-22 07:40:11.516: E/AndroidRuntime(3369): at android.view.View.performClick(View.java:4240)
10-22 07:40:11.516: E/AndroidRuntime(3369): at android.view.View$PerformClick.run(View.java:17721)