Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Fields](https://developer.android.com/reference/android/media/MediaTimestamp#lfields) \| [Ctors](https://developer.android.com/reference/android/media/MediaTimestamp#pubctors) \| [Methods](https://developer.android.com/reference/android/media/MediaTimestamp#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaTimestamp#inhmethods)

# MediaTimestamp

*** ** * ** ***

` public final class MediaTimestamp `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.MediaTimestamp |

<br />

*** ** * ** ***

An immutable object that represents the linear correlation between the media time and the system time. It contains the media clock rate, together with the media timestamp of an anchor frame and the system time when that frame was presented or is committed to be presented.

The phrase "present" means that audio/video produced on device is detectable by an external observer off device. The time is based on the implementation's best effort, using whatever knowledge is available to the system, but cannot account for any delay unknown to the implementation. The anchor frame could be any frame, including a just-rendered frame, or even a theoretical or in-between frame, based on the source of the MediaTimestamp. When the anchor frame is a just-rendered one, the media time stands for current position of the playback or recording.
**See also:**

- `https://developer.android.com/reference/android/media/MediaSync#getTimestamp()`
- `https://developer.android.com/reference/android/media/MediaPlayer#getTimestamp()`

## Summary

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/media/MediaTimestamp` | `https://developer.android.com/reference/android/media/MediaTimestamp#TIMESTAMP_UNKNOWN` An unknown media timestamp value |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/MediaTimestamp#MediaTimestamp(long,%20long,%20float)(long mediaTimeUs, long nanoTimeNs, float clockRate) ` Constructor. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/media/MediaTimestamp#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. |
| ` long` | ` https://developer.android.com/reference/android/media/MediaTimestamp#getAnchorMediaTimeUs()() ` Get the media time of the anchor in microseconds. |
| ` long` | ` https://developer.android.com/reference/android/media/MediaTimestamp#getAnchorSystemNanoTime()() ` Get the `https://developer.android.com/reference/java/lang/System#nanoTime()` corresponding to the media time in nanoseconds. |
| ` long` | ` https://developer.android.com/reference/android/media/MediaTimestamp#getAnchorSytemNanoTime()() ` *This method was deprecated in API level 29. use `https://developer.android.com/reference/android/media/MediaTimestamp#getAnchorSystemNanoTime()` instead.* |
| ` float` | ` https://developer.android.com/reference/android/media/MediaTimestamp#getMediaClockRate()() ` Get the rate of the media clock in relation to the system time. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/media/MediaTimestamp#toString()() ` Returns a string representation of the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Fields

### TIMESTAMP_UNKNOWN

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final MediaTimestamp TIMESTAMP_UNKNOWN
```

An unknown media timestamp value

<br />

## Public constructors

### MediaTimestamp

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MediaTimestamp (long mediaTimeUs, 
                long nanoTimeNs, 
                float clockRate)
```

Constructor.

<br />

| Parameters ||
|---|---|
| `mediaTimeUs` | `long`: the media time of the anchor in microseconds <br /> |
| `nanoTimeNs` | `long`: the `https://developer.android.com/reference/java/lang/System#nanoTime()` corresponding to the media time in nanoseconds. <br /> |
| `clockRate` | `float`: the rate of the media clock in relation to the system time. Value is between 0.0f and `https://developer.android.com/reference/java/lang/Float#MAX_VALUE` inclusive <br /> |

## Public methods

### equals

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object obj)
```

Indicates whether some other object is "equal to" this one.

The `equals` method implements an equivalence relation on non-null object references:

- It is *reflexive*: for any non-null reference value `x`, `x.equals(x)` should return `true`.
- It is *symmetric*: for any non-null reference values `x` and `y`, `x.equals(y)` should return `true` if and only if `y.equals(x)` returns `true`.
- It is *transitive*: for any non-null reference values `x`, `y`, and `z`, if `x.equals(y)` returns `true` and `y.equals(z)` returns `true`, then `x.equals(z)` should return `true`.
- It is *consistent*: for any non-null reference values `x` and `y`, multiple invocations of `x.equals(y)` consistently return `true` or consistently return `false`, provided no information used in `equals` comparisons on the objects is modified.
- For any non-null reference value `x`, `x.equals(null)` should return `false`.

An equivalence relation partitions the elements it operates on into *equivalence classes*; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

<br />

| Parameters ||
|---|---|
| `obj` | `Object`: the reference object with which to compare. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this object is the same as the obj argument; `false` otherwise. <br /> |

### getAnchorMediaTimeUs

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getAnchorMediaTimeUs ()
```

Get the media time of the anchor in microseconds.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getAnchorSystemNanoTime

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getAnchorSystemNanoTime ()
```

Get the `https://developer.android.com/reference/java/lang/System#nanoTime()` corresponding to the media time in nanoseconds.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getAnchorSytemNanoTime

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getAnchorSytemNanoTime ()
```

<br />

**This method was deprecated in API level 29.**   

use `https://developer.android.com/reference/android/media/MediaTimestamp#getAnchorSystemNanoTime()` instead.

Get the `https://developer.android.com/reference/java/lang/System#nanoTime()` corresponding to the media time in nanoseconds.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getMediaClockRate

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float getMediaClockRate ()
```

Get the rate of the media clock in relation to the system time.

It is 1.0 if media clock advances in sync with the system clock; greater than 1.0 if media clock is faster than the system clock; less than 1.0 if media clock is slower than the system clock.

<br />

| Returns ||
|---|---|
| `float` | Value is between 0.0f and `https://developer.android.com/reference/java/lang/Float#MAX_VALUE` inclusive <br /> |

### toString

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |