Reputation: 9023
I need to play pcm file through AudioTrack, I want know to that it has finished playing or not?
My code:
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() { public
void run() {
if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
System.out.println("stop"); } // doSomethingUseful();
}
}, 0, 1, TimeUnit.SECONDS);
then
do{
if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
// stop(); // myAudioRecorder.release(); // stop(); //
myAudioRecorder = new MediaRecorder(); // myAudioRecorder.stop();
System.out.println("stopped......................."); //
myAudioRecorder.release(); r_start = false; }
} while (r_start == true);
But none of above is working.
How can I know it has finished playing?
Upvotes: 2
Views: 2877
Reputation: 9023
audioTrack
.setPlaybackPositionUpdateListener(new OnPlaybackPositionUpdateListener() {
@Override
public void onPeriodicNotification(AudioTrack track) {
// TODO Auto-generated method stub
}
@Override
public void onMarkerReached(AudioTrack track) {
// TODO Auto-generated method stub
stop();
// messageHandler.sendMessage(messageHandler.obtainMessage(PLAYBACK_END_REACHED));
}
});
Upvotes: 0
Reputation: 229
Refer to this post How to tell when AudioTrack object has finished playing?
This solution using "OnPlaybackPositionUpdateListener" that notifies when playback reached specific mark by marking length of audio length.
Upvotes: 3