dev → main: Android UPnP/Sonos transport parity + server stream URL extension #79
@@ -189,6 +189,7 @@ class MinstrelForwardingPlayer(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
super.seekTo(mediaItemIndex, positionMs)
|
super.seekTo(mediaItemIndex, positionMs)
|
||||||
|
remoteState.markUserTransport(SystemClock.elapsedRealtime())
|
||||||
scope.launch {
|
scope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
active.avTransport.seekToTrack(mediaItemIndex + 1)
|
active.avTransport.seekToTrack(mediaItemIndex + 1)
|
||||||
@@ -214,6 +215,7 @@ class MinstrelForwardingPlayer(
|
|||||||
// then delegate to Sonos Next. PollLoop reconciles cursor via
|
// then delegate to Sonos Next. PollLoop reconciles cursor via
|
||||||
// Track index if they diverge.
|
// Track index if they diverge.
|
||||||
super.seekToNextMediaItem()
|
super.seekToNextMediaItem()
|
||||||
|
remoteState.markUserTransport(SystemClock.elapsedRealtime())
|
||||||
scope.launch {
|
scope.launch {
|
||||||
runCatching { active.avTransport.next() }
|
runCatching { active.avTransport.next() }
|
||||||
.onFailure { handleSoapFailure(active, it) }
|
.onFailure { handleSoapFailure(active, it) }
|
||||||
@@ -234,6 +236,7 @@ class MinstrelForwardingPlayer(
|
|||||||
// Super first for immediate local cursor advance (UI feedback);
|
// Super first for immediate local cursor advance (UI feedback);
|
||||||
// then delegate to Sonos Previous. PollLoop reconciles.
|
// then delegate to Sonos Previous. PollLoop reconciles.
|
||||||
super.seekToPreviousMediaItem()
|
super.seekToPreviousMediaItem()
|
||||||
|
remoteState.markUserTransport(SystemClock.elapsedRealtime())
|
||||||
scope.launch {
|
scope.launch {
|
||||||
runCatching { active.avTransport.previous() }
|
runCatching { active.avTransport.previous() }
|
||||||
.onFailure { handleSoapFailure(active, it) }
|
.onFailure { handleSoapFailure(active, it) }
|
||||||
|
|||||||
@@ -525,11 +525,19 @@ class PlayerController @Inject constructor(
|
|||||||
val newPos = effectivePosition.coerceAtLeast(0)
|
val newPos = effectivePosition.coerceAtLeast(0)
|
||||||
val newDur = effectiveDuration(upnpActive, remoteState.durationMs, controller.duration)
|
val newDur = effectiveDuration(upnpActive, remoteState.durationMs, controller.duration)
|
||||||
val newBuf = controller.bufferedPosition.coerceAtLeast(0)
|
val newBuf = controller.bufferedPosition.coerceAtLeast(0)
|
||||||
// Forward-only. If desiredIdx < queueIndex, the user just pressed Next
|
// Two guards against undoing the user's transport action while
|
||||||
// and Sonos's poll hasn't caught up yet -- walking backward would undo
|
// remoteState is mid-refresh from the next SOAP poll:
|
||||||
// their press (logcat 2026-06-04 showed exactly that jump-back-then-
|
// 1. Forward-only: a backward move from desiredIdx < queueIndex
|
||||||
// forward cycle). Mirrors maybeSyncLocalCursor's forward-only policy.
|
// would undo a Next press (logcat 2026-06-04).
|
||||||
val trackChanged = desiredIdx > current.queueIndex && desiredIdx in queueRefs.indices
|
// 2. Transport-ack lockout: even forward moves are ignored within
|
||||||
|
// TRANSPORT_ACK_WINDOW_MS of a user transport action, so a Prev
|
||||||
|
// press isn't undone by a stale remoteState reading the older
|
||||||
|
// pre-press track.
|
||||||
|
val sinceTransport = SystemClock.elapsedRealtime() - remoteState.lastUserTransportAtMs
|
||||||
|
val inTransportAckWindow = sinceTransport < TRANSPORT_ACK_WINDOW_MS
|
||||||
|
val trackChanged = !inTransportAckWindow &&
|
||||||
|
desiredIdx > current.queueIndex &&
|
||||||
|
desiredIdx in queueRefs.indices
|
||||||
val somethingChanged = trackChanged ||
|
val somethingChanged = trackChanged ||
|
||||||
current.isPlaying != effectiveIsPlaying ||
|
current.isPlaying != effectiveIsPlaying ||
|
||||||
current.positionMs != newPos ||
|
current.positionMs != newPos ||
|
||||||
@@ -667,6 +675,7 @@ class PlayerController @Inject constructor(
|
|||||||
const val MINSTREL_SOURCE_KEY: String = "minstrel_source"
|
const val MINSTREL_SOURCE_KEY: String = "minstrel_source"
|
||||||
private const val MS_PER_SECOND = 1_000L
|
private const val MS_PER_SECOND = 1_000L
|
||||||
private const val MAX_INTERPOLATION_DRIFT_MS = 5_000L
|
private const val MAX_INTERPOLATION_DRIFT_MS = 5_000L
|
||||||
|
private const val TRANSPORT_ACK_WINDOW_MS = 2_000L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,18 @@ class RemotePlayerState @Inject constructor() {
|
|||||||
@Volatile var lastError: Throwable? = null; private set
|
@Volatile var lastError: Throwable? = null; private set
|
||||||
@Volatile var trackNumber: Int = 0; private set
|
@Volatile var trackNumber: Int = 0; private set
|
||||||
|
|
||||||
|
// SystemClock.elapsedRealtime() at the last user-initiated transport
|
||||||
|
// (next/prev/seekToIndex). PlayerController.tickPositionPoll uses this to
|
||||||
|
// suppress track-change adjustments during the window where remoteState
|
||||||
|
// hasn't yet refreshed from the next SOAP poll -- without it the polling
|
||||||
|
// tick would walk the cursor back to Sonos's pre-press track and undo
|
||||||
|
// user input. Set from MinstrelForwardingPlayer's transport overrides.
|
||||||
|
@Volatile var lastUserTransportAtMs: Long = 0L; private set
|
||||||
|
|
||||||
|
fun markUserTransport(nowMs: Long) {
|
||||||
|
lastUserTransportAtMs = nowMs
|
||||||
|
}
|
||||||
|
|
||||||
@Volatile private var consecutivePollFailures: Int = 0
|
@Volatile private var consecutivePollFailures: Int = 0
|
||||||
|
|
||||||
fun applyPositionInfo(positionMs: Long, durationMs: Long, trackUri: String, trackNumber: Int) {
|
fun applyPositionInfo(positionMs: Long, durationMs: Long, trackUri: String, trackNumber: Int) {
|
||||||
@@ -64,6 +76,7 @@ class RemotePlayerState @Inject constructor() {
|
|||||||
lastError = null
|
lastError = null
|
||||||
consecutivePollFailures = 0
|
consecutivePollFailures = 0
|
||||||
trackNumber = 0
|
trackNumber = 0
|
||||||
|
lastUserTransportAtMs = 0L
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user