0

代码:

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)
4

1 回答 1

0

看起来你根本没有更新你bytesRead的,它总是保持在 0。这样你while()就永远运行(在你的情况下 - 直到 OutOfMemory)
我也没有注意到你从 is(你的输入流)读取任何数据到缓冲区(audio_data )

于 2013-10-22T12:46:30.230 回答