Hi everyone,
I am playing audio and video streams that need to be in sync. After playing around with several android devices, I realized that each of them has a different audio playback latency.
I am using AudioTrack and and ran some tests. It seems that even if audiotrack.getPlaybackHeadPosition() is called by the two devices in exactly the same millisecond (to be precise, there might be a 2ms difference) and even if audiotrack.getPlaybackHeadPosition() returns exactly the same result (i.e. the audiotrack head is positioned on the same frame, at the same time in both devices), still the audio that comes out of one device is always slightly ahead of the audio which comes out of the second device.
It also seems that the results are in line with the latency value I get when running the following code:
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
try{
Method m = am.getClass().getMethod("getOutputLatency", int.class);
Integer latency = (Integer)m.invoke(am, AudioManager.STREAM_MUSIC);
mLogger.error(" reported latency is " + latency.intValue());
}catch(Exception e){
mLogger.error(" could not determine latency");
}
In other words - the audio which comes out of the devices which report a greater latency, is lagging.
The problem is that the above code does not run on all android devices. Any idea how I can directly extract the above "hardware latency value" without being dependent on the exact device model and android version?
Thanks!
Ilan