Monday, April 7, 2014

How can we know has played AudioTrack end


 
m_out_buf_size1 = android.media.AudioTrack.getMinBufferSize (16000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
m_out_trk1 = new AudioTrack (AudioManager.STREAM_MUSIC, 16000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
Math.max (m_out_buf_size1 * 3, 10240),
AudioTrack.MODE_STREAM);
byte [] bData = ...; / / where to get the data you want to play
int offset = 0;
int markerInFrames = bData.length / m_out_buf_size1;
m_out_trk1.setPositionNotificationPeriod (1);
m_out_trk1.setNotificationMarkerPosition (Math.max (markerInFrames-1, 0));
m_out_trk1.setPlaybackPositionUpdateListener (this);
/ / Call m_out_trk1.write/.play/.stop
...

/ / Then, to achieve the following code, but found that sound normal output, but no output onMarkerReached string, where is the problem?
@ Override
public void onMarkerReached (AudioTrack track) {
/ / TODO Auto-generated method stub
Log.d (TAG, "onMarkerReached");
}

@ Override
public void onPeriodicNotification (AudioTrack track) {
/ / TODO Auto-generated method stub
Log.d (TAG, "onPeriodicNotification");
}



Looking to find information, said there are many problems AudioTrack realize, do not understand how can we know AudioTrack player has an end?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
If MediaPlayer, you can set the play finished listening
setOnCompletionListener
Look up documentation AudioTrack finishes playing there listening interface
Reply:
Reply # 1, AudioTrack find information means that you should use setPlaybackPositionUpdateListener and setNotificationMarkerPosition
Reply:
Also, if you can get the current time and total time played, make a comparison, a difference of a certain time (eg 1s) is considered to play within finished.
Reply:
setPlaybackPositionUpdateListener can, is to play the next play for a long tune callback function. This is usually because sampleRate etc. are fixed, you reckon on it.
Reply:
references, 4th Floor freshui reply:
setPlaybackPositionUpdateListener can, is to play the next play for a long tune callback function. This is usually because sampleRate etc. are fixed, you reckon on it.


Do you have examples of code? My code is always how the callback function can not be called.
Reply:
There should be appropriate to the upper EOS event delivery, JAVA layer may not be captured in this message listner
Reply:
references, 5th Floor lazy_2010 reply:
references, 4th Floor freshui reply:
setPlaybackPositionUpdateListener can, is to play the next play for a long tune callback function. This is usually because sampleRate etc. are fixed, you reckon on it.


Do you have examples of code? My code is always how the callback function can not be called.

Only C + + example - this is not difficult, if there is source code, then under AudioTrack.java / .cpp add trace debugging to see how it
Reply:
No android source code, from where to download ah.
Reply:
http://android.git.kernel.org/
Reply:
Well, assuming we know everything, but that did not teach me to understand, alas.
Reply:
It seems that there are other people have this problem
http://code.google.com/p/android/issues/detail?id=2563
Reply:
I guess something like this: you must
mode with MODE_STATICsetNotificationMarkerPosition
Write must be placed in the front! Frames should subtract a job, or you put the frame divided by two, you should be able to successfully
callback
And MODE_STATIC mode in Android 4.2 under question a lot, too dizzy
With MODE_STREAM mode, do not know can use the callback success

No comments:

Post a Comment