AudioTrack skipping after pause and resume

Posted by Markus Drösser on Stack Overflow See other posts from Stack Overflow or by Markus Drösser
Published on 2011-01-11T21:49:45Z Indexed on 2011/01/11 21:53 UTC
Read the original article Hit count: 151

Filed under:
|
|

Hi, here is the problem.

I play a wav file that i recorded earlier without problems. but when i call audiotrack.pause() and audiotrack.start() again after some waiting, it skips some frames of the file. why is that?

here is my play listener

        // Start playback
        audioTrack.setPlaybackPositionUpdateListener(new OnPlaybackPositionUpdateListener() {

            @Override
            public void onPeriodicNotification(AudioTrack track) {

                try {


                    if(ramfile!=null && ramfile.read(buffer)==-1)
                    {                                                   
                        audioTrack.release();
                        audioTrack = null;
                        ramfile.close();
                        playing=false;
                    }
                    else
                    {
                        audioTrack.write(buffer, 0, buffer.length);
                    }
                } catch (IOException e) {

                    try {
                        ramfile.close();
                        playing=false;
                    } catch (IOException e1) {

                    }
                }
            }

            @Override
            public void onMarkerReached(AudioTrack track) {
                playing=false;
                track.release();
            }
        });

© Stack Overflow or respective owner

Related posts about android

Related posts about audio