In Android the getPlaybackHeadPosition() method of AudioTrack class returns the playback head position expressed in frames ,what is its equivalent value in milli seconds?
Asked
Active
Viewed 5,772 times
2 Answers
21
I'm guessing that it would be
( track.getPlaybackHeadPosition( ) / track.getSampleRate( ) ) * 1000.0
In other words, the number of frames played divided by the number of frames per second. You then multiply the result by 1000 to get milliseconds.
A frame consists of one sample per channel and so should be equivalent to sample rate.
For example, if getPlaybackHeadPosition( )
returns 8654
and getSampleRate( )
returns 8000
then the time since the start of the track would be ( 8654 / 8000 ) * 1000
or 1081.75ms
. (Assuming floating point arithmetic)

Nick
- 25,026
- 7
- 51
- 83
-
for example, if the audio has 8000 samples/sec, (track.getPlaybackHeadPosition( )/8) gives you current playback head position in milli seconds. – Raneez Ahmed May 01 '12 at 11:32
-
Correct. I'll add an example to the answer. – Nick May 01 '12 at 11:37
-
So a "frame" is the same as a sample? – Edward Falk Dec 20 '12 at 00:32
-
Or with plain integer math (no floats): track.getPlaybackHeadPosition() * 1000 / track.getSampleRate() – Pointer Null Apr 22 '14 at 16:23
0
The answer by @Nike is right。
But there is a problem。
If we call the MediaExtractor.seekTo
method, AudioTrack.getPlaybackHeadPosition()
returns accumulate value。
MediaExtractor.getSampleTime() / 1000
is the right ms for current position.
You can check it out!

peerless2012
- 179
- 1
- 7