Remove nested import of Player.Events
from PlayerExtensions.listen
This makes it clearer that the part inside and outside the parentheses are clearly different, and not "just" a reference to `Player.Events`. Specifically this syntax is showing that the function has a `Player` "receiver", **and** is a function from `Player.Events` to `Unit`. https://kotlinlang.org/docs/lambdas.html#function-types PiperOrigin-RevId: 663293405
This commit is contained in:
parent
ee27334f06
commit
873ec1544e
@ -18,7 +18,6 @@ package androidx.media3.common
|
|||||||
|
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import androidx.core.os.HandlerCompat
|
import androidx.core.os.HandlerCompat
|
||||||
import androidx.media3.common.Player.Events
|
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlin.coroutines.resumeWithException
|
import kotlin.coroutines.resumeWithException
|
||||||
@ -45,7 +44,7 @@ import kotlinx.coroutines.withContext
|
|||||||
* terminate due to an exception or cancellation.
|
* terminate due to an exception or cancellation.
|
||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
suspend fun Player.listen(onEvents: Player.(Events) -> Unit): Nothing {
|
suspend fun Player.listen(onEvents: Player.(Player.Events) -> Unit): Nothing {
|
||||||
if (Looper.myLooper() == applicationLooper) {
|
if (Looper.myLooper() == applicationLooper) {
|
||||||
listenImpl(onEvents)
|
listenImpl(onEvents)
|
||||||
} else
|
} else
|
||||||
@ -79,7 +78,7 @@ suspend fun Player.listen(onEvents: Player.(Events) -> Unit): Nothing {
|
|||||||
* guarantees are critical for responding to events with frame-perfect timing and become more
|
* guarantees are critical for responding to events with frame-perfect timing and become more
|
||||||
* relevant in the context of front-end UI development (e.g. using Compose).
|
* relevant in the context of front-end UI development (e.g. using Compose).
|
||||||
*/
|
*/
|
||||||
private suspend fun Player.listenImpl(onEvents: Player.(Events) -> Unit): Nothing {
|
private suspend fun Player.listenImpl(onEvents: Player.(Player.Events) -> Unit): Nothing {
|
||||||
lateinit var listener: PlayerListener
|
lateinit var listener: PlayerListener
|
||||||
try {
|
try {
|
||||||
suspendCancellableCoroutine<Nothing> { continuation ->
|
suspendCancellableCoroutine<Nothing> { continuation ->
|
||||||
@ -93,13 +92,13 @@ private suspend fun Player.listenImpl(onEvents: Player.(Events) -> Unit): Nothin
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class PlayerListener(
|
private class PlayerListener(
|
||||||
private val onEvents: Player.(Events) -> Unit,
|
private val onEvents: Player.(Player.Events) -> Unit,
|
||||||
private val continuation: CancellableContinuation<Nothing>,
|
private val continuation: CancellableContinuation<Nothing>,
|
||||||
) : Player.Listener {
|
) : Player.Listener {
|
||||||
|
|
||||||
val isCancelled: AtomicBoolean = AtomicBoolean(false)
|
val isCancelled: AtomicBoolean = AtomicBoolean(false)
|
||||||
|
|
||||||
override fun onEvents(player: Player, events: Events) {
|
override fun onEvents(player: Player, events: Player.Events) {
|
||||||
try {
|
try {
|
||||||
if (!isCancelled.get()) {
|
if (!isCancelled.get()) {
|
||||||
player.onEvents(events)
|
player.onEvents(events)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user