Share via


AudioTrack.GetTimestamp(AudioTimestamp) Method

Definition

Poll for a timestamp on demand.

[Android.Runtime.Register("getTimestamp", "(Landroid/media/AudioTimestamp;)Z", "GetGetTimestamp_Landroid_media_AudioTimestamp_Handler")]
public virtual bool GetTimestamp (Android.Media.AudioTimestamp? timestamp);
[<Android.Runtime.Register("getTimestamp", "(Landroid/media/AudioTimestamp;)Z", "GetGetTimestamp_Landroid_media_AudioTimestamp_Handler")>]
abstract member GetTimestamp : Android.Media.AudioTimestamp -> bool
override this.GetTimestamp : Android.Media.AudioTimestamp -> bool

Parameters

timestamp
AudioTimestamp

a reference to a non-null AudioTimestamp instance allocated and owned by caller.

Returns

true if a timestamp is available, or false if no timestamp is available. If a timestamp is available, the AudioTimestamp instance is filled in with a position in frame units, together with the estimated time when that frame was presented or is committed to be presented. In the case that no timestamp is available, any supplied instance is left unaltered. A timestamp may be temporarily unavailable while the audio clock is stabilizing, or during and immediately after a route change. A timestamp is permanently unavailable for a given route if the route does not support timestamps. In this case, the approximate frame position can be obtained using #getPlaybackHeadPosition. However, it may be useful to continue to query for timestamps occasionally, to recover after a route change.

Attributes

Remarks

Poll for a timestamp on demand.

If you need to track timestamps during initial warmup or after a routing or mode change, you should request a new timestamp periodically until the reported timestamps show that the frame position is advancing, or until it becomes clear that timestamps are unavailable for this route.

After the clock is advancing at a stable rate, query for a new timestamp approximately once every 10 seconds to once per minute. Calling this method more often is inefficient. It is also counter-productive to call this method more often than recommended, because the short-term differences between successive timestamp reports are not meaningful. If you need a high-resolution mapping between frame position and presentation time, consider implementing that at application level, based on low-resolution timestamps.

The audio data at the returned position may either already have been presented, or may have not yet been presented but is committed to be presented. It is not possible to request the time corresponding to a particular position, or to request the (fractional) position corresponding to a particular time. If you need such features, consider implementing them at application level.

Java documentation for android.media.AudioTrack.getTimestamp(android.media.AudioTimestamp).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to