1

如何检测 AudioTrack 是否已完成播放?不简单!!!我需要在另一个(入队)之后立即触摸此代码不起作用...当按 2 次时,第一个不结束,同时播放两个声音...

private void getNextAudio() {
    try{            

        byte[] buffer = playlist.poll();
        if (buffer != null) {

            AudioTrack myatrack = getAudioTrack(buffer);                
            myatrack.setPlaybackPositionUpdateListener( new OnPlaybackPositionUpdateListener() {            

                public void onPeriodicNotification(AudioTrack track) {

                }

                public void onMarkerReached(AudioTrack track) {             
                    Log.d(TAG, "onMarker - estado: " + track.getPlayState());

                    if(track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED){

                        track.flush();
                        track.stop();
                        track.release();

                        getNextAudio();
                    }                               
                }
            });             

            if (myatrack != null) {
                // toco o audio.
                myatrack.play();
            }
        }else{
            Log.d(TAG,"Finish");
        }
    }catch(NoSuchElementException ex){
        Log.d(TAG,"No such element");           
    }
}

再次感谢!马特乌斯

4

0 回答 0