diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 353b8340..c0ebd382 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 = 238 - versionName = "0.108.78-companion-queue" + versionCode = 239 + versionName = "0.108.79-companion-queue" } 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 5e54606f..2ef0b7e7 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.78\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.79\"") + (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.78\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.79\"" + (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/OrbitCompanion.kt b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt index a4c21ed2..04b6f483 100644 --- a/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt +++ b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt @@ -139,6 +139,8 @@ internal object OrbitCompanion { catchUpShelves(screen.channels(), nowMs).flatMap { it.entries }.firstOrNull { it.channel.number == number && it.show.startMs == startMs } const val QUEUE_MAX = 5 + /** How long before the programme's end the queue takes over. */ + const val QUEUE_LEAD_MS = 2_500L var queue by mutableStateOf>(emptyList()) /** Queue [number] live after the programme on now, or a Catch Up programme ([catchUpStartMs]); null when it can't be. */ @@ -169,8 +171,12 @@ internal object OrbitCompanion { fun follow(screen: CompanionScreen, anchor: Pair?, nowMs: Long): Pair? { val head = queue.firstOrNull() ?: return null val channel = screen.channels().firstOrNull { it.number == screen.selected() } ?: return anchor - val on = screen.selected() to channel.at(nowMs + screen.offset()).startMs - if (anchor == null || !screen.watching() || anchor.first != on.first || anchor == on) return on + val programme = channel.at(nowMs + screen.offset()) + val on = screen.selected() to programme.startMs + // It switches a moment before the end (Paul, 6 November 2026: the next programme began loading first, then the queue + // took over), so the channel's own next programme never starts. + val ending = anchor == on && programme.endMs - (nowMs + screen.offset()) <= QUEUE_LEAD_MS + if (anchor == null || !screen.watching() || anchor.first != on.first || (anchor == on && !ending)) return on queue = queue.drop(1) val offset = head.catchUpStartMs?.let { start -> catchUpEntry(screen, head.number, start, nowMs)?.offsetFrom(nowMs) } if (head.catchUpStartMs == null || offset != null) screen.tune(head.number, offset ?: 0) 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 b615b459..c1eca1ca 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.78") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.79") 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/test/java/tv/orbit/classic/PhoneLinkTest.kt b/android/app/src/test/java/tv/orbit/classic/PhoneLinkTest.kt index 1a5d6589..8fa9aada 100644 --- a/android/app/src/test/java/tv/orbit/classic/PhoneLinkTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/PhoneLinkTest.kt @@ -210,15 +210,17 @@ class PhoneLinkTest { assertEquals(guideTitleParts(companionChannels[1].at(end).media.item.title).first, OrbitCompanion.queue[0].title) var anchor = OrbitCompanion.follow(screen, null, now) assertEquals(101 to start, anchor) - anchor = OrbitCompanion.follow(screen, anchor, end - 1_000); assertTrue(tuned.isEmpty()) + anchor = OrbitCompanion.follow(screen, anchor, end - 10_000); assertTrue(tuned.isEmpty()) // Changing channel moves the wait to the new programme instead of playing. - selected = 308; anchor = OrbitCompanion.follow(screen, anchor, end - 500); assertTrue(tuned.isEmpty()) - selected = 101; anchor = OrbitCompanion.follow(screen, anchor, end - 400); assertTrue(tuned.isEmpty()) + selected = 308; anchor = OrbitCompanion.follow(screen, anchor, end - 9_000); assertTrue(tuned.isEmpty()) + selected = 101; anchor = OrbitCompanion.follow(screen, anchor, end - 8_000); assertTrue(tuned.isEmpty()) // Not watching: it waits. watching = false; anchor = OrbitCompanion.follow(screen, anchor, end + 1_000); assertTrue(tuned.isEmpty()) watching = true; anchor = OrbitCompanion.follow(screen, anchor, end + 2_000); assertTrue(tuned.isEmpty()) val nextEnd = companionChannels[0].at(end + 2_000).endMs - OrbitCompanion.follow(screen, anchor, nextEnd + 1_000) + anchor = OrbitCompanion.follow(screen, anchor, nextEnd - 5_000); assertTrue(tuned.isEmpty()) + // A moment before the end, so the channel's own next programme never starts. + OrbitCompanion.follow(screen, anchor, nextEnd - 2_000) assertEquals(listOf(308 to 0L), tuned); assertTrue(OrbitCompanion.queue.isEmpty()) // Five at most. repeat(5) { assertNotNull(OrbitCompanion.enqueue(screen, 101, null, now)) }