cast: carry the TV's playback up and the app's commands down
- Commit
a2b858def3d6ae8ad209db256f33c4024f5baa8c- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-24 00:21 UTC (3 months ago)
- Parents
58a3124
Diff
cast/src/main/java/com/vayunmathur/cast/platform/CastController.kt
diff --git a/cast/src/main/java/com/vayunmathur/cast/platform/CastController.kt b/cast/src/main/java/com/vayunmathur/cast/platform/CastController.ktindex 833a77ff89..4e17450587 100644--- a/cast/src/main/java/com/vayunmathur/cast/platform/CastController.kt+++ b/cast/src/main/java/com/vayunmathur/cast/platform/CastController.kt@@ -207,13 +207,22 @@ object CastController { * * Set and cleared by `ContentCastService` alongside [onContentSessionEnded], and for the same * reasons: one session, one callback, and a command has to reach the app once rather than be a- * current value worth observing.+ * current value. * * Null during screen mirroring, which has no transport to control - and [startWatch] does not even * offer the dispatch in that case, so a stray command never reaches this far. */ var onPlaybackCommand: ((PlaybackCommand) -> Unit)? = null + /**+ * Notified with the *television's* playback, during a served session.+ *+ * The inverse of [reportPlaybackState] and set on the same terms as [onPlaybackCommand]. Only a+ * served session produces these: it is the one case where the TV holds the player, so it is the one+ * case where the phone has to be told rather than telling.+ */+ var onTvPlaybackState: ((PlaybackState) -> Unit)? = null+ /** * The name of the app that last completed `CastPickerActivity`, resolved from its * `callingPackage`.@@ -692,6 +701,18 @@ object CastController { scope.launch { mutex.withLock { activeClient.playMedia(media) } } } + /**+ * Ask the TV to do something, in a served session.+ *+ * Under [mutex] like [playMedia] and for the same reason: one socket, several writers. Silently+ * does nothing with no session, because the caller is an app's transport and a session that has+ * just ended is the ordinary reason for a press to go nowhere.+ */+ fun sendPlaybackCommand(command: PlaybackCommand) {+ val activeClient = client ?: return+ scope.launch { mutex.withLock { activeClient.sendPlaybackCommand(command) } }+ }+ private fun startWatch( appContext: Context, activeClient: MirrorClient,@@ -717,7 +738,12 @@ object CastController { } else { null }- val reason = activeClient.awaitEnd(dispatch)+ val states: ((PlaybackState) -> Unit)? = if (transportControls) {+ { state -> onTvPlaybackState?.invoke(state) }+ } else {+ null+ }+ val reason = activeClient.awaitEnd(dispatch, states) // **Another path may already own this teardown.** Closing the socket is what unblocks the // read above, and [endCodecConfigFailure] closes it deliberately - so a return from // `awaitEnd` is not proof that the TV ended the session. Whoever cancelled this job is@@ -754,9 +780,15 @@ object CastController { * * A content session is the case where the control channel can go completely silent while * everything is working: the TV fetches the media over HTTPS and owns its own clock, so unless- * the app volunteers playback snapshots there is nothing for the phone to say. Both ends give a- * read 60 seconds, so silence used to end the session on whichever side read first - which is- * what tore a session down a minute in while a track was still being encoded.+ * one end volunteers playback snapshots there is nothing to say. Both ends give a read 60 seconds,+ * so silence used to end the session on whichever side read first - which is what tore a session+ * down a minute in while a track was still being encoded.+ *+ * **Stopped when the session is, even though `ContentEnded` hands the channel back rather than+ * closing it.** Keeping it running would hold that channel open indefinitely - and a second+ * content session on a channel whose [watchJob] is still parked in a blocking read has two readers+ * of one socket, so the reply to its `CONTENT_SESSION` goes to the wrong one. Letting the idle+ * channel lapse at the read timeout is what bounds that window to a minute rather than for ever. * * Under [mutex] like every other writer, because this is one more thread writing one socket. */@@ -775,6 +807,11 @@ object CastController { val appContext = context.applicationContext scope.launch { endContentSession(CastContract.REASON_CLIENT_CLOSED)+ // **Before [stopEngine], which closes the proxy.** The TV owns its own clock and buffer, so+ // told afterwards it would keep playing what it had already fetched and then fail its next+ // fetch against a port that has gone - an error card instead of the idle screen. `proxy`+ // being set is exactly "this was a served session"; nothing else needs telling.+ if (proxy != null) client?.let { mutex.withLock { it.sendContentEnded() } } stopEngine() _mirrorPhase.value = MirrorPhase.Idle _sessionState.update {@@ -953,7 +990,8 @@ object CastController { proxy = null // Cancelled here rather than only in `teardown`: `stopMirroring` deliberately leaves the // control channel and `watchJob` alive, so a ping loop left running would keep pinging on- // behalf of a session that has ended.+ // behalf of a session that has ended - and hold that channel open for ever, which is more+ // than `ContentEnded`'s handback can safely be given. See [startKeepAlive]. pingJob?.cancel() pingJob = null }@@ -968,6 +1006,7 @@ object CastController { val notify = onContentSessionEnded ?: return onContentSessionEnded = null onPlaybackCommand = null+ onTvPlaybackState = null notify(reason) }
cast/src/main/java/com/vayunmathur/cast/platform/MirrorClient.kt
diff --git a/cast/src/main/java/com/vayunmathur/cast/platform/MirrorClient.kt b/cast/src/main/java/com/vayunmathur/cast/platform/MirrorClient.ktindex 8a2a685a4c..5c68257697 100644--- a/cast/src/main/java/com/vayunmathur/cast/platform/MirrorClient.kt+++ b/cast/src/main/java/com/vayunmathur/cast/platform/MirrorClient.kt@@ -6,6 +6,7 @@ import com.vayunmathur.cast.domain.ClientFailure import com.vayunmathur.cast.network.ControlSocket import com.vayunmathur.cast.protocol.Bye import com.vayunmathur.cast.protocol.ByeReason+import com.vayunmathur.cast.protocol.ContentEnded import com.vayunmathur.cast.protocol.ContentReady import com.vayunmathur.cast.protocol.ContentSession import com.vayunmathur.cast.protocol.DecoderLimits@@ -353,6 +354,37 @@ class MirrorClient( .onFailure { Log.w(TAG, "could not send the playback state", it) } } + /**+ * Ask the TV to do something, in a served session.+ *+ * The reverse of the direction this message runs for screen mirroring, and the honest one for a+ * file: the television has the player, so this is what a pause pressed anywhere on the phone turns+ * into. Non-throwing for [sendPlaybackState]'s reasons - a dead socket is [awaitEnd]'s to report -+ * but logged, because unlike a snapshot each of these is a user action rather than a tick.+ */+ fun sendPlaybackCommand(command: PlaybackCommand) {+ Log.i(TAG, "asking the TV for ${command.action}${command.value?.let { " $it" }.orEmpty()}")+ runCatching { socket.send(command) }+ .onFailure { Log.w(TAG, "could not send ${command.action}", it) }+ }++ /**+ * Tell the TV the content session is over, and that the connection is not.+ *+ * **Nothing else tells it.** The TV owns its own clock and buffer, so a session that simply stops+ * being served carries on playing whatever it had already fetched and then fails its next request+ * against a proxy that has gone - an error card where the idle screen belongs. Which is also why+ * this must be sent *before* the proxy stops.+ *+ * Deliberately not [sayGoodbye]: that ends the connection, and with it the paired-and-connected+ * state the user just used. Closing one cast should leave the TV ready for the next.+ */+ fun sendContentEnded() {+ Log.i(TAG, "telling '$receiverName' the content session is over")+ runCatching { socket.send(ContentEnded) }+ .onFailure { Log.w(TAG, "could not end the content session", it) }+ }+ /** * Put a keep-alive on the control channel, so the TV's read deadline does not expire. *@@ -378,14 +410,18 @@ class MirrorClient( * the caller has to act on, not a note for a human. * * **A dispatch loop rather than a drain.** This used to discard everything that was not a `Bye`,- * which was right while the TV had nothing else to say. It has a remote now, and its- * [PlaybackCommand]s arrive on this same socket - and cannot arrive anywhere else, because there- * is one socket with one read position and this is already the only reader.+ * which was right while the TV had nothing else to say. It has a transport now, and both halves of+ * it arrive on this same socket - and cannot arrive anywhere else, because there is one socket with+ * one read position and this is already the only reader. *- * [onCommand] is null for screen mirroring, which has no transport to control. A command that- * turns up anyway is logged and dropped rather than acted on.+ * [onCommand] is null for screen mirroring, which has no transport to control. [onState] is null+ * for anything that is not a served session, where the TV has no player to describe. Either+ * message turning up anyway is logged and dropped rather than acted on. */- fun awaitEnd(onCommand: ((PlaybackCommand) -> Unit)? = null): String? {+ fun awaitEnd(+ onCommand: ((PlaybackCommand) -> Unit)? = null,+ onState: ((PlaybackState) -> Unit)? = null,+ ): String? { while (true) { val next = socket.receive() ?: return null when (val message = next.message) {@@ -403,6 +439,9 @@ class MirrorClient( onCommand(message) } }+ // The television's own player, in a served session. Not logged: this arrives twice a+ // second, and a line per snapshot would bury everything else about the session.+ is PlaybackState -> onState?.invoke(message) // The echo of our own keep-alive. Nothing to do with it: having read it is the // whole effect, because that is what pushed this socket's read deadline out. is Ping -> {}
cast/src/main/java/com/vayunmathur/cast/service/ContentCastService.kt
diff --git a/cast/src/main/java/com/vayunmathur/cast/service/ContentCastService.kt b/cast/src/main/java/com/vayunmathur/cast/service/ContentCastService.ktindex 9ea1b8c1ff..cd480172d6 100644--- a/cast/src/main/java/com/vayunmathur/cast/service/ContentCastService.kt+++ b/cast/src/main/java/com/vayunmathur/cast/service/ContentCastService.kt@@ -49,7 +49,7 @@ class ContentCastService : Service() { private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main) - /** Where `MSG_SESSION_READY`, `MSG_SESSION_ENDED` and `MSG_PLAYBACK_COMMAND` go. */+ /** Where `MSG_SESSION_READY`, `MSG_SESSION_ENDED`, `MSG_PLAYBACK_COMMAND` and `MSG_TV_PLAYBACK_STATE` go. */ private var client: Messenger? = null /** True between a successful open and the session ending, so nothing is reported twice. */@@ -102,6 +102,15 @@ class ContentCastService : Service() { } true }+ CastContract.MSG_SEND_PLAYBACK_COMMAND -> {+ // Dropped with no session, like the two above: the television it would drive is no+ // longer this client's.+ if (sessionOpen) {+ msg.data?.toPlaybackCommand()+ ?.let { CastController.sendPlaybackCommand(it) }+ }+ true+ } else -> false } },@@ -177,6 +186,11 @@ class ContentCastService : Service() { CastController.onPlaybackCommand = { command -> scope.launch { send(playbackCommand(command)) } }+ // The half that only a served session has: the TV holds the player, so its state+ // has to reach the client rather than the other way round.+ CastController.onTvPlaybackState = { state ->+ scope.launch { send(tvPlaybackState(state)) }+ } sendServing(result) } }@@ -230,6 +244,7 @@ class ContentCastService : Service() { sessionOpen = false CastController.onContentSessionEnded = null CastController.onPlaybackCommand = null+ CastController.onTvPlaybackState = null // The app's descriptors are ours until the session ends, and nothing else will close them. resources.close() // Back to a paired-but-idle TV rather than a dropped session: the pairing is per device and@@ -289,8 +304,29 @@ private fun Bundle.toPlayMedia(): PlayMedia = PlayMedia( // trip but plays, where a refused item would simply be silence. mimeType = getString(CastContract.KEY_RESOURCE_TYPE).orEmpty(), durationMs = getLong(CastContract.KEY_MEDIA_DURATION_MS),+ startPositionMs = getLong(CastContract.KEY_START_POSITION_MS), ) +/**+ * The press a client sent, as the message the TV understands, or null for an action this build does+ * not know.+ *+ * Matched through [sdkAction] rather than a second hand-written table, which is what keeps this+ * exhaustive for free: adding an action to the protocol enum fails to compile *there*, and this+ * follows without being able to disagree with it. Null rather than a fallback for an unrecognised int,+ * because a command invented by a newer SDK is one this build has nothing to do with.+ */+private fun Bundle.toPlaybackCommand(): PlaybackCommand? {+ val action = getInt(CastContract.KEY_ACTION, -1)+ val matched = PlaybackAction.entries.firstOrNull { it.sdkAction == action } ?: return null+ val value = if (containsKey(CastContract.KEY_ACTION_VALUE)) {+ getDouble(CastContract.KEY_ACTION_VALUE)+ } else {+ null+ }+ return PlaybackCommand(matched, value)+}+ /** The command the TV sent, as the `Message` the SDK reads. See [Bundle.toPlaybackState]. */ private fun playbackCommand(command: PlaybackCommand): Message = Message.obtain(null, CastContract.MSG_PLAYBACK_COMMAND).apply {@@ -300,6 +336,28 @@ private fun playbackCommand(command: PlaybackCommand): Message = } } +/**+ * The television's own playback, as the `Message` the SDK reads.+ *+ * The inverse of [Bundle.toPlaybackState], and `hasNext`/`hasPrevious` are carried through unchanged+ * even though the TV cannot know them: the keys exist, the client ignores them, and dropping them here+ * would be a second place that has to agree about which fields are meaningful in which direction.+ */+private fun tvPlaybackState(state: PlaybackState): Message =+ Message.obtain(null, CastContract.MSG_TV_PLAYBACK_STATE).apply {+ data = Bundle().apply {+ putLong(CastContract.KEY_POSITION_MS, state.positionMs)+ putLong(CastContract.KEY_DURATION_MS, state.durationMs)+ putBoolean(CastContract.KEY_PLAYING, state.playing)+ putBoolean(CastContract.KEY_BUFFERING, state.buffering)+ putFloat(CastContract.KEY_SPEED, state.speed)+ putFloat(CastContract.KEY_VOLUME, state.volume)+ putBoolean(CastContract.KEY_HAS_NEXT, state.hasNext)+ putBoolean(CastContract.KEY_HAS_PREVIOUS, state.hasPrevious)+ putBoolean(CastContract.KEY_ENDED, state.ended)+ }+ }+ /** * The SDK's int for a protocol action. *
sdk/cast/src/main/java/com/vayunmathur/sdk/cast/CastClient.kt
diff --git a/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/CastClient.kt b/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/CastClient.ktindex 9ed7a2fc9f..14d850e891 100644--- a/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/CastClient.kt+++ b/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/CastClient.kt@@ -81,8 +81,10 @@ class CastClient(context: Context) { * A live content session: Cast is serving this app's own media to the TV. * * Nothing to draw into and nothing to write, because nothing is being encoded. The TV fetches- * byte ranges of whatever the app named and decodes them itself, so the app's only remaining- * job is to answer [CastResourceProvider] and to keep sending [reportPlaybackState].+ * byte ranges of whatever the app named and decodes them itself - so it also owns the clock, the+ * buffer and the position, which is why the app's remaining jobs are to answer+ * [CastResourceProvider], to *listen* on [onPlaybackState], and to send what the user presses+ * through [sendCommand]. [reportPlaybackState] has nothing to say here: there is no local player. * * There is no granted geometry either: the TV plays the media at its own size, which is the * point - the frame is no longer being squeezed through an encoder this phone had to choose.@@ -111,6 +113,20 @@ class CastClient(context: Context) { */ var onCommand: ((PlaybackCommand) -> Unit)? = null + /**+ * Called with the *television's* playback, in a content session, twice a second and on any change.+ *+ * The inverse of [reportPlaybackState], and the one that matters when the TV is serving this app's+ * media: there is no player running here, so this is the only account of where playback is. A+ * client that leaves it null casts perfectly and then shows a player frozen at 0:00 whose buttons+ * drive nothing anybody can hear.+ *+ * `hasNext` and `hasPrevious` should be ignored - the queue is this app's, and the TV never saw it.+ *+ * Runs on the main thread, like [onCommand].+ */+ var onPlaybackState: ((PlaybackState) -> Unit)? = null+ private var service: Messenger? = null private var bound = false @@ -139,6 +155,12 @@ class CastClient(context: Context) { if (open) PlaybackCommand.from(msg.data)?.let { onCommand?.invoke(it) } true }+ CastContract.MSG_TV_PLAYBACK_STATE -> {+ // Dropped after the session, for [onCommand]'s reason turned around: a snapshot+ // applied during teardown would leave a local player describing a dead TV.+ if (open) msg.data?.let { onPlaybackState?.invoke(PlaybackState.from(it)) }+ true+ } CastContract.MSG_RESOURCE_REQUEST -> { onResourceRequest(msg.data) true@@ -334,10 +356,14 @@ class CastClient(context: Context) { * Call it again for the next item - there is no playlist, because the queue stays here where the * ordering, the artwork and the metadata are. *+ * [startPositionMs] is what makes handing playback over keep its place instead of restarting the+ * track. A resource still being written cannot honour it, because there is no length to seek+ * against, and the TV then starts at the beginning.+ * * Silent and non-throwing, like [reportPlaybackState]: a session that has just ended is the * common reason for this to go nowhere, and the client already learns that through [onEnded]. */- fun play(resourceId: String, mimeType: String, durationMs: Long = 0) {+ fun play(resourceId: String, mimeType: String, durationMs: Long = 0, startPositionMs: Long = 0) { if (!open) return val remote = service ?: return val message = Message.obtain(null, CastContract.MSG_PLAY_MEDIA).apply {@@ -345,6 +371,7 @@ class CastClient(context: Context) { putString(CastContract.KEY_RESOURCE_ID, resourceId) putString(CastContract.KEY_RESOURCE_TYPE, mimeType) putLong(CastContract.KEY_MEDIA_DURATION_MS, durationMs)+ putLong(CastContract.KEY_START_POSITION_MS, startPositionMs) } } try {@@ -353,6 +380,28 @@ class CastClient(context: Context) { } } + /**+ * Ask the television to do something, in a content session.+ *+ * The inverse of [onCommand]: the TV holds the player, so play, pause, seek and speed have to+ * travel to it however the user asked - the app's own screen, a notification, a headset button, a+ * car. [PlaybackAction.Next] and [PlaybackAction.Previous] are **not** for this: the queue is+ * here, so advancing means calling [play] with the next item.+ *+ * Silent and non-throwing, like [play] and [reportPlaybackState], and for the same reasons.+ */+ fun sendCommand(command: PlaybackCommand) {+ if (!open) return+ val remote = service ?: return+ val message = Message.obtain(null, CastContract.MSG_SEND_PLAYBACK_COMMAND).apply {+ data = command.toBundle()+ }+ try {+ remote.send(message)+ } catch (_: RemoteException) {+ }+ }+ /** * Say that a resource offered with an unknown length has finished being written. *@@ -388,6 +437,7 @@ class CastClient(context: Context) { fun close() { onEnded = null onCommand = null+ onPlaybackState = null pending = null resources = null // Shut down after clearing the provider so a request already in flight finds nothing to
sdk/cast/src/main/java/com/vayunmathur/sdk/cast/Playback.kt
diff --git a/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/Playback.kt b/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/Playback.ktindex 7e941f14ea..8d08b91da1 100644--- a/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/Playback.kt+++ b/sdk/cast/src/main/java/com/vayunmathur/sdk/cast/Playback.kt@@ -3,7 +3,7 @@ package com.vayunmathur.sdk.cast import android.os.Bundle /**- * Where playback is, for the television to draw a seek bar from.+ * Where playback is, for the end that cannot see the player to draw a seek bar from. * * **A deliberate second definition of `:cast:protocol`'s message of the same name, not a reuse of * it.** This module is the public client contract: every app that casts compiles against it, and@@ -12,6 +12,11 @@ import android.os.Bundle * sides and owns the translation, so the duplication is one file wide and two functions deep, and it * buys a public API that cannot leak the protocol. *+ * Used in both directions: an app that draws into a `Surface` reports its own player with+ * [CastClient.reportPlaybackState], and an app whose media the TV is *serving* is told about the+ * television's player through [CastClient.onPlaybackState]. Which end owns the truth is whichever end+ * owns the player.+ * * A snapshot rather than a delta: absolute in every field, so a lost one repairs itself on the next * heartbeat and there is no sequence number to get wrong. */@@ -22,9 +27,9 @@ data class PlaybackState( /** * Whether media is actually advancing. *- * Report the player's own "is playing" rather than its play-when-ready flag: the TV extrapolates- * position between snapshots, and a stall reported as playing runs its seek bar ahead of the- * picture and then snaps it back.+ * Report the player's own "is playing" rather than its play-when-ready flag: the receiver+ * extrapolates position between snapshots, and a stall reported as playing runs its seek bar ahead+ * of the picture and then snaps it back. */ val playing: Boolean, /** For a spinner. Distinct from [playing], because a stall is not a pause. */@@ -37,10 +42,19 @@ data class PlaybackState( * Whether there is anything to skip to. * * Carried because the TV cannot know - what comes next is this app's own idea of a queue - and a- * remote offering a button that does nothing is worse than one offering none.+ * remote offering a button that does nothing is worse than one offering none. Always the app's,+ * and meaningless coming *from* the television. */ val hasNext: Boolean = false, val hasPrevious: Boolean = false,+ /**+ * The item finished on its own, so a queue can advance.+ *+ * Only meaningful coming from the television. Its own field rather than a position-against-duration+ * reading, which cannot be told apart from a pause at the end of a track - and has no duration to+ * compare against at all while a resource is still being written.+ */+ val ended: Boolean = false, ) { internal fun toBundle(): Bundle = Bundle().apply { putLong(CastContract.KEY_POSITION_MS, positionMs)@@ -51,11 +65,37 @@ data class PlaybackState( putFloat(CastContract.KEY_VOLUME, volume) putBoolean(CastContract.KEY_HAS_NEXT, hasNext) putBoolean(CastContract.KEY_HAS_PREVIOUS, hasPrevious)+ putBoolean(CastContract.KEY_ENDED, ended)+ }++ internal companion object {+ /**+ * Read one back, for the television's own playback.+ *+ * Defaults rather than refusals for the optional fields, exactly as `:cast` does going the+ * other way: an absent speed means 1x, and a snapshot rejected for lacking one would leave+ * every surface on the phone frozen.+ */+ internal fun from(data: Bundle): PlaybackState = PlaybackState(+ positionMs = data.getLong(CastContract.KEY_POSITION_MS),+ durationMs = data.getLong(CastContract.KEY_DURATION_MS),+ playing = data.getBoolean(CastContract.KEY_PLAYING),+ buffering = data.getBoolean(CastContract.KEY_BUFFERING),+ speed = data.getFloat(CastContract.KEY_SPEED, 1f),+ volume = data.getFloat(CastContract.KEY_VOLUME, 1f),+ hasNext = data.getBoolean(CastContract.KEY_HAS_NEXT),+ hasPrevious = data.getBoolean(CastContract.KEY_HAS_PREVIOUS),+ ended = data.getBoolean(CastContract.KEY_ENDED),+ ) } } /**- * A press on the television's remote.+ * A press on whichever transport the user reached for.+ *+ * Arrives from the television's remote through [CastClient.onCommand] when the app is drawing into a+ * `Surface`, and goes *to* the television through [CastClient.sendCommand] when the television is the+ * one with the player. * * [value] is the action's argument for the actions that take one - milliseconds for * [PlaybackAction.SeekTo], a multiplier for [PlaybackAction.SetSpeed], 0..1 for@@ -66,6 +106,11 @@ data class PlaybackCommand( val action: PlaybackAction, val value: Double? = null, ) {+ internal fun toBundle(): Bundle = Bundle().apply {+ putInt(CastContract.KEY_ACTION, action.wire)+ value?.let { putDouble(CastContract.KEY_ACTION_VALUE, it) }+ }+ companion object { /** * Read one back, or null for an action this build does not know.@@ -87,7 +132,7 @@ data class PlaybackCommand( } /**- * What the remote asked for.+ * What the transport asked for. * * The [wire] value is what crosses the `Bundle`; the Kotlin names are free to change. An enum is not * put in the `Bundle` directly because a `Serializable` enum there is a class-loading problem waiting@@ -98,20 +143,21 @@ enum class PlaybackAction(internal val wire: Int) { Pause(CastContract.ACTION_PAUSE), /**- * Whichever of the two the player is not currently doing.+ * Whichever of the two the end holding the player is not currently doing. *- * Its own action rather than the TV resolving it from the last snapshot: that snapshot can be half- * a second old, and two quick presses resolved against it would both send the same thing.+ * Its own action rather than the sender resolving it from the last snapshot: that snapshot can be+ * half a second old, and two quick presses resolved against it would both send the same thing. */ Toggle(CastContract.ACTION_TOGGLE), /** Absolute position, in milliseconds. */ SeekTo(CastContract.ACTION_SEEK_TO), - /** The app's own skip interval, so the two ends cannot disagree about how far it is. */+ /** A discrete skip, by whatever interval the end holding the player uses for one. */ SkipForward(CastContract.ACTION_SKIP_FORWARD), SkipBack(CastContract.ACTION_SKIP_BACK), + /** Always the app's to answer, whichever way it arrived: the queue is the app's. */ Next(CastContract.ACTION_NEXT), Previous(CastContract.ACTION_PREVIOUS),