1

i am working on a Audio Player which have contains feeding to AudioTrack, by the help of native i am getting sound from audiotrack , but the thing is after some time i am getting stack overflow error in my AudioTrack class. I have increase heap size in .manifest but it doesn't change anything. my log is:

08-07 11:53:49.843: E/AndroidRuntime(23539): FATAL EXCEPTION: Thread-1298
08-07 11:53:49.843: E/AndroidRuntime(23539): Process: com.example.player, PID: 23539
08-07 11:53:49.843: E/AndroidRuntime(23539): java.lang.StackOverflowError
08-07 11:53:49.843: E/AndroidRuntime(23539):    at android.media.AudioTrack.write(AudioTrack.java:1141)
08-07 11:53:49.843: E/AndroidRuntime(23539):    at com.example.player.MusicService.recursive(MusicService.java:100)
08-07 11:53:49.843: E/AndroidRuntime(23539):    at com.example.player.MusicService.recursive(MusicService.java:105)
08-07 11:53:49.843: E/AndroidRuntime(23539):    at com.example.player.MusicService.recursive(MusicService.java:105)
08-07 11:53:49.843: E/AndroidRuntime(23539):    at com.example.player.MusicService.recursive(MusicService.java:105)

please help me . i am stuck in it. i am using recursive rather than do while for some reasons.. my method is ...

    void recursive() {
        // Log.e("", "reccursive called");
        if (paused) {
            Log.e("", "is paused        " + paused);
            signalControl.doWait();
        }
        err = NativeWrapper.decodeMP3(minBufferSize * 2, buffer);
        // Log.e("", "" + buffer.length);
        // byte[] bufferbyte = ShortToByte_Twiddle_Method(buffer);
        // Log.e("", "mp3 decoding by native");

        track.write(buffer, 0, minBufferSize); // Write
        track.flush();
        // Log.e("", "write to track");
        // track.flush();
        if (err != MPG123_DONE) {
            recursive();
        }

    }
Varun Chaudhary
  • 370
  • 4
  • 19

1 Answers1

-2

Have a look at this SO answer. Hope this is helpful. In case you don't wont recursive method, you can check this code snippet.

Quote from answer "there is a way to increase your stack size, although you might not be able to do it in the main UI Thread, by making use of the Thread object parameters as:

ThreadGroup group = new ThreadGroup("threadGroup");
new Thread(group, runnableObject, "YourThreadName", 2000000).start();

this willl increase the stack size to 2M.

Community
  • 1
  • 1
Arpan
  • 613
  • 7
  • 18