diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 0e2a172d..cb822605 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 223 - versionName = "0.108.63-quicker-tuning" + versionCode = 224 + versionName = "0.108.64-picture-handover" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt index 72cb7e0b..c9f2fa90 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI } /** The sign-in headers for this kind of server. */ internal fun authHeaders(token: String?): Map = when (kind) { - ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.63\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.64\"") + (token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap()) - ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.63\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.64\"" + (token?.let { ", Token=\"$it\"" } ?: "")) } /** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */ diff --git a/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt b/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt index e95e1c65..724f1a85 100644 --- a/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt +++ b/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt @@ -29,6 +29,12 @@ import kotlinx.coroutines.withContext internal class LiveStream(val channelNumber: Int, val startMs: Long, val plan: EmbyPlaybackPlan, private val player: ExoPlayer) { private var claimed = false val available get() = !claimed + /** + * Handed to full screen. The picture then leaves it running even though full screen, which opens in its own window, + * only claims it a moment later (Paul, 6 November 2026: choosing full screen still re-tuned, as the picture let go of + * the stream before full screen had taken it). + */ + var handedOff = false fun claim(): ExoPlayer? = if (claimed) null else player.also { claimed = true } fun discard(session: EmbySampleSession) { claim()?.let { closeLiveStream(session, plan, it) } } } @@ -39,7 +45,7 @@ internal class LiveHandoff { /** Call before going full screen. The picture then leaves its stream running for the player to take. */ fun handOver(channelNumber: Int) { android.util.Log.i("OrbitSchedule", "picture handover channel=$channelNumber pictureOpen=${open != null} sameChannel=${open?.channelNumber == channelNumber}") - handed = open?.takeIf { it.channelNumber == channelNumber }; open = null + handed = open?.takeIf { it.channelNumber == channelNumber }?.also { it.handedOff = true }; open = null } fun take(): LiveStream? = handed.also { handed = null } /** Left by the full-screen player on the way out, for the picture to carry on with. */ @@ -164,7 +170,7 @@ private fun GuideLivePlayer(session: EmbySampleSession, plan: EmbyPlaybackPlan, player.removeListener(listener) if (handoff.open === stream) handoff.open = null // Handed to the full-screen player, which owns it from here. - if (handoff.handed !== stream && stream.available) stream.discard(session) + if (!stream.handedOff && stream.available) stream.discard(session) } } LaunchedEffect(player, ready) { diff --git a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt index 0004bec1..99fee131 100644 --- a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt +++ b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt @@ -56,6 +56,8 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC if (stream != null && stream.channelNumber == channel.number && stream.startMs == current.startMs && clockOffsetMs == 0L) stream else { stream?.discard(session); null } } + // A handed stream full screen didn't end up using is closed with it, so it never plays on unseen. + DisposableEffect(Unit) { onDispose { handed?.discard(session) } } val next = shows[1] val identsOn = remember { OrbitSettings(settingsContext).idents } val specialOn = remember { OrbitSettings(settingsContext).specialIdents } @@ -66,7 +68,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC // The squeeze-back (Paul, 6 November 2026): over the last minute, with the next programme loading from its start. val squeezeOn = remember { OrbitSettings(settingsContext).squeezeBack } val calmMotion = remember { OrbitSettings(settingsContext).reduceMotion } - val squeezing = squeezeOn && channel is ScheduledChannel && squeezeBackDue(channel.number, current.startMs, current.endMs, next.startMs, now, if (identsHere) identMs else 0L, clockOffsetMs) + val squeezing = squeezeOn && channel is ScheduledChannel && squeezeBackDue(channel.number, current.startMs, current.endMs, next.startMs, now, if (identsHere) identMs else 0L, clockOffsetMs, squeezeLength(current.media.item.type)) val squeeze by androidx.compose.animation.core.animateFloatAsState(if (squeezing) 1f else 0f, if (calmMotion) androidx.compose.animation.core.snap() else androidx.compose.animation.core.tween(1_000), label = "squeeze") val phase = if (identsHere) identPhase(current.startMs, current.endMs, now, identMs, if (squeezeOn) SQUEEZE_MS + IDENT_LOAD_AHEAD_MS else IDENT_LOAD_AHEAD_MS) else IdentPhase.None diff --git a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt index 9412d72d..3e94ab75 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -39,7 +39,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B next.instanceFollowRedirects = false next.connectTimeout = 10_000 next.readTimeout = 20_000 - next.setRequestProperty("User-Agent", "OrbitTV/0.108.63") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.64") next.setRequestProperty("Accept-Encoding", "identity") session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) } if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) { diff --git a/android/app/src/main/java/tv/orbit/classic/SqueezeBack.kt b/android/app/src/main/java/tv/orbit/classic/SqueezeBack.kt index c7329a9b..0c5c0560 100644 --- a/android/app/src/main/java/tv/orbit/classic/SqueezeBack.kt +++ b/android/app/src/main/java/tv/orbit/classic/SqueezeBack.kt @@ -31,12 +31,19 @@ internal const val SQUEEZE_MS = 60_000L internal const val SQUEEZE_SHRINK = .46f private const val SQUEEZE_SHORTEST_MS = 10 * 60_000L -/** Whether the squeeze-back is showing now: the minute before the ident (or before the end, with no ident). */ -internal fun squeezeBackDue(number: Int, startMs: Long, endMs: Long, nextStartMs: Long, nowMs: Long, identMs: Long, offsetMs: Long): Boolean { +/** + * How long the squeeze-back lasts (Paul, 6 November 2026): a TV show's end goes small for its last 22 seconds, a film's for + * its last minute, as films have longer credits. + */ +internal const val SQUEEZE_SHOW_MS = 22_000L +internal fun squeezeLength(type: String) = if (type == "Movie") SQUEEZE_MS else SQUEEZE_SHOW_MS + +/** Whether the squeeze-back is showing now: the [lengthMs] before the ident (or before the end, with no ident). */ +internal fun squeezeBackDue(number: Int, startMs: Long, endMs: Long, nextStartMs: Long, nowMs: Long, identMs: Long, offsetMs: Long, lengthMs: Long = SQUEEZE_MS): Boolean { if (offsetMs != 0L || number == DRIVE_IN_NUMBER || endMs - startMs < SQUEEZE_SHORTEST_MS || nextStartMs != endMs) return false if (number == TOTS_NUMBER && totsMood(nowMs).evening) return false val until = endMs - identMs - return nowMs >= until - SQUEEZE_MS && nowMs < until + return nowMs >= until - lengthMs && nowMs < until } /** Each channel's cast member in the squeeze-back: Ollie on Tots, the others shared round the rest. */ diff --git a/android/app/src/test/java/tv/orbit/classic/SqueezeBackTest.kt b/android/app/src/test/java/tv/orbit/classic/SqueezeBackTest.kt index bc5c9230..5c83c73f 100644 --- a/android/app/src/test/java/tv/orbit/classic/SqueezeBackTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/SqueezeBackTest.kt @@ -45,4 +45,12 @@ class SqueezeBackTest { assertNull(squeezeCast(TOTS_NUMBER)); assertNotNull(squeezeCast(106)) assertEquals(squeezeCast(106), squeezeCast(106)) } + + @Test fun aShowGoesSmallForItsLast22SecondsAFilmForItsLastMinute() { + assertEquals(SQUEEZE_SHOW_MS, squeezeLength("Episode")); assertEquals(SQUEEZE_MS, squeezeLength("Movie")) + val start = 0L; val end = 30 * 60_000L + assertFalse(squeezeBackDue(106, start, end, end, end - 30_000, 0, 0, squeezeLength("Episode"))) + assertTrue(squeezeBackDue(106, start, end, end, end - 20_000, 0, 0, squeezeLength("Episode"))) + assertTrue(squeezeBackDue(106, start, end, end, end - 50_000, 0, 0, squeezeLength("Movie"))) + } }