# Clock

# Clock

Artifact:[androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/Clock.java+class:androidx.media3.common.util.Clock)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/util/Clock "View this page in Java")

<br />

```
@UnstableApi
interface Clock
```

<br />

Known direct subclasses  
[FakeClock](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeClock),[SystemClock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/SystemClock)  

|-------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [FakeClock](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeClock)      | Fake[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock)implementation that allows to[advance the time](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeClock#advanceTime(long))manually to trigger pending timed messages. |
| [SystemClock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/SystemClock) | The standard implementation of[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock), an instance of which is available via[DEFAULT](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#DEFAULT()).                           |

*** ** * ** ***

An interface through which system clocks can be read and[HandlerWrapper](https://developer.android.com/reference/kotlin/androidx/media3/common/util/HandlerWrapper)s created. The[DEFAULT](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#DEFAULT())implementation must be used for all non-test cases.

## Summary

|                                            ### Constants                                             |
|------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock)`!` | [DEFAULT](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#DEFAULT()) Default[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock)to use for all non-test cases. |

|                                              ### Public functions                                              |
|----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [HandlerWrapper](https://developer.android.com/reference/kotlin/androidx/media3/common/util/HandlerWrapper)`!` | [createHandler](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#createHandler(android.os.Looper,android.os.Handler.Callback))`(` ` looper: `[Looper](https://developer.android.com/reference/android/os/Looper.html)`!,` ` callback: @`[UnknownInitialization](https://checkerframework.org/api/org/checkerframework/checker/initialization/qual/UnknownInitialization.html)` `[Handler.Callback](https://developer.android.com/reference/android/os/Handler.Callback.html)`?` `)` Creates a[HandlerWrapper](https://developer.android.com/reference/kotlin/androidx/media3/common/util/HandlerWrapper)using a specified looper and a specified callback for handling messages. |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                  | [currentTimeMillis](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#currentTimeMillis())`()` Returns the current time in milliseconds since the Unix Epoch.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                  | [elapsedRealtime](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#elapsedRealtime())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                  | [nanoTime](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#nanoTime())`()` See[nanoTime](https://developer.android.com/reference/java/lang/System.html#nanoTime())                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                  | [onThreadBlocked](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#onThreadBlocked())`()` Notifies the clock that the current thread is about to be blocked and won't return until a condition on another thread becomes true.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                  | [uptimeMillis](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock#uptimeMillis())`()`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

## Constants

### DEFAULT

```
const val DEFAULT: Clock!
```

Default[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock)to use for all non-test cases.  

## Public functions

### createHandler

```
fun createHandler(
    looper: Looper!,
    callback: @UnknownInitialization Handler.Callback?
): HandlerWrapper!
```

Creates a[HandlerWrapper](https://developer.android.com/reference/kotlin/androidx/media3/common/util/HandlerWrapper)using a specified looper and a specified callback for handling messages.  

|                                                              See also                                                              |
|------------------------------------------------------------------------------------------------------------------------------------|---|
| [Handler](https://developer.android.com/reference/android/os/Handler.html#Handler(android.os.Looper, android.os.Handler.Callback)) |   |

### currentTimeMillis

```
fun currentTimeMillis(): Long
```

Returns the current time in milliseconds since the Unix Epoch.  

|                                                See also                                                |
|--------------------------------------------------------------------------------------------------------|---|
| [currentTimeMillis](https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()) |   |

### elapsedRealtime

```
fun elapsedRealtime(): Long
```  

|                                                 See also                                                 |
|----------------------------------------------------------------------------------------------------------|---|
| [elapsedRealtime](https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()) |   |

### nanoTime

```
fun nanoTime(): Long
```

See[nanoTime](https://developer.android.com/reference/java/lang/System.html#nanoTime())  

### onThreadBlocked

```
fun onThreadBlocked(): Unit
```

Notifies the clock that the current thread is about to be blocked and won't return until a condition on another thread becomes true.

Should be a no-op for all non-test cases.  

### uptimeMillis

```
fun uptimeMillis(): Long
```  

|                                              See also                                              |
|----------------------------------------------------------------------------------------------------|---|
| [uptimeMillis](https://developer.android.com/reference/android/os/SystemClock.html#uptimeMillis()) |   |