From 86e90efc029057782b43f5d60b27702845fb1c10 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Tue, 3 Nov 2026 19:41:43 +0000 Subject: [PATCH] =?UTF-8?q?0.95.1:=20when=20a=20programme's=20file=20ends?= =?UTF-8?q?=20before=20its=20slot,=20play=20and=20hold=20the=20channel=20i?= =?UTF-8?q?dent=20(NEXT=20AT=20=E2=80=A6)=20instead=20of=20a=20black=20scr?= =?UTF-8?q?een?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 (1M context) --- android/app/build.gradle.kts | 4 ++-- .../main/java/tv/orbit/classic/EmbyClient.kt | 2 +- .../tv/orbit/classic/EmbyPlaybackDialog.kt | 5 ++++- .../src/main/java/tv/orbit/classic/Idents.kt | 14 +++++++++++--- .../tv/orbit/classic/SampleChannelScreens.kt | 19 ++++++++++++++++--- .../tv/orbit/classic/SecureMediaDataSource.kt | 2 +- .../test/java/tv/orbit/classic/IdentTest.kt | 9 +++++++++ docs/VERIFICATION-0.95.1.md | 13 +++++++++++++ 8 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 docs/VERIFICATION-0.95.1.md diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index a3ec3f6a..6466d592 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 = 119 - versionName = "0.95.0-riot-vhs-rewind-polish" + versionCode = 120 + versionName = "0.95.1-early-end-ident" } buildFeatures { compose = true } compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 } 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 9efd083f..267ad0c9 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI connection.connectTimeout = 10_000 connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000 connection.setRequestProperty("Accept", "application/json") - connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.95.0\"") + connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.95.1\"") request.token?.let { connection.setRequestProperty("X-Emby-Token", it) } if (request.method == "POST") { val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8) diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt index c80297a6..276fb1bb 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt @@ -49,7 +49,9 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl /** A window that stays open across programmes. Without one, this opens its own. */ window: PlaybackWindow? = null, /** Called when the programme's first picture is on screen, so anything held over the changeover can go. */ - onFirstFrame: (() -> Unit)? = null) { + onFirstFrame: (() -> Unit)? = null, + /** Called when a scheduled programme's file runs out before its slot ends. */ + onEndedEarly: (() -> Unit)? = null) { val context = LocalContext.current val logoSetting = remember { OrbitSettings(context).channelLogo } var failure by remember { mutableStateOf(null) } @@ -203,6 +205,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl } } override fun onPlaybackStateChanged(state: Int) { + if (state == Player.STATE_ENDED && scheduled != null) onEndedEarly?.invoke() if (state == Player.STATE_READY) { if (scheduled != null && !joinedSchedule) { joinedSchedule = true diff --git a/android/app/src/main/java/tv/orbit/classic/Idents.kt b/android/app/src/main/java/tv/orbit/classic/Idents.kt index 614499ab..7944e235 100644 --- a/android/app/src/main/java/tv/orbit/classic/Idents.kt +++ b/android/app/src/main/java/tv/orbit/classic/Idents.kt @@ -48,6 +48,12 @@ internal fun identLength(number: Int, atMs: Long = 0) = when (number) { internal enum class IdentPhase { None, LoadNext, Showing } +/** Under this much left, a file running out is just its credits ending a moment early, which the ident covers anyway. */ +internal const val EARLY_END_GRACE_MS = 3_000L + +/** A file that stops well before its slot ends: Emby listed it longer than it really runs. */ +internal fun finishedEarly(nowMs: Long, endMs: Long) = endMs - nowMs > EARLY_END_GRACE_MS + /** The ident covers the end of a show, usually its credits, so the next one still starts exactly on time. */ internal fun identPhase(startMs: Long, endMs: Long, nowMs: Long, identMs: Long): IdentPhase = when { endMs - startMs < IDENT_SHORTEST_PROGRAMME_MS -> IdentPhase.None @@ -82,7 +88,9 @@ internal fun loadNextPlayer(context: Context, session: EmbySampleSession, plan: /** The channel's ident over the end of the show, saying what's next. A channel with no film of its own gets its logo over the next show's artwork. */ @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) @Composable -internal fun IdentOverlay(session: EmbySampleSession, channel: SampleChannel, next: SampleBroadcast, identMs: Long, startedLateMs: Long) { +internal fun IdentOverlay(session: EmbySampleSession, channel: SampleChannel, next: SampleBroadcast, identMs: Long, startedLateMs: Long, + /** Filling time after a programme ended early: says when the next one starts, and keeps to a still picture if idents are off. */ + early: Boolean = false) { val context = LocalContext.current val mood = if (channel.number == TOTS_NUMBER) totsMood(next.startMs) else null val settings = remember { OrbitSettings(context) } @@ -92,7 +100,7 @@ internal fun IdentOverlay(session: EmbySampleSession, channel: SampleChannel, ne val video = identVideo(channel.number, next.startMs) // With idents off, Tots still says goodbye with a picture that doesn't move. if (mood != null && !settings.idents) Image(painterResource(mood.still), null, Modifier.fillMaxSize()) - else if (video != null) { + else if (video != null && !(early && !settings.idents)) { val player = remember(video) { ExoPlayer.Builder(context).build().apply { setMediaItem(MediaItem.fromUri(RawResourceDataSource.buildRawResourceUri(video))) @@ -111,7 +119,7 @@ internal fun IdentOverlay(session: EmbySampleSession, channel: SampleChannel, ne } } Column(Modifier.align(Alignment.BottomStart).padding(start = 40.dp, bottom = 32.dp).background(Navy.copy(alpha = .72f)).padding(horizontal = 14.dp, vertical = 8.dp)) { - Text("NEXT", color = Color(0xFFD5DCEA), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp) + Text(if (early) "NEXT AT ${clock(next.startMs)}" else "NEXT", color = Color(0xFFD5DCEA), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp) Text(guideTitleParts(next.media.item.title).first, color = Color.White, fontSize = 20.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) } } 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 2966a4ff..888e690e 100644 --- a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt +++ b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt @@ -118,6 +118,10 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC // The ident playing out, held on its last frame until the next programme's first picture is on screen. var heldIdent by remember(channel) { mutableStateOf(null) } LaunchedEffect(phase == IdentPhase.Showing, next.startMs) { if (phase == IdentPhase.Showing) heldIdent = next } + // A file can stop before its slot ends, when Emby lists it longer than it really runs (a Tots Night Garden on + // 3 November stopped 3 minutes early). Instead of a black screen, the channel's ident plays and holds its last + // frame, saying what's next and when, until the next programme's booked start. The schedule itself doesn't move. + var endedEarly by remember(channel) { mutableStateOf(null) } LaunchedEffect(heldIdent) { val held = heldIdent ?: return@LaunchedEffect // However the next programme fares, the screen never stays on the ident for long. @@ -138,7 +142,15 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC onHandBack = { running -> if (handoff != null && clockOffsetMs == 0L) { handoff.returned = LiveStream(channel.number, current.startMs, plan, running); true } else false }, - window = window, onFirstFrame = { if (heldIdent?.startMs == current.startMs) heldIdent = null }) + window = window, onFirstFrame = { if (heldIdent?.startMs == current.startMs) heldIdent = null }, + onEndedEarly = { + val at = System.currentTimeMillis() + clockOffsetMs + if (channel is ScheduledChannel && next.startMs == current.endMs && finishedEarly(at, current.endMs) && heldIdent == null) { + PlaybackNotes.add(notes, "channel=${channel.number} endedEarlyMs=${current.endMs - at} item=${current.media.item.id}") + android.util.Log.w("OrbitSchedule", "channel=${channel.number} endedEarlyMs=${current.endMs - at} item=${current.media.item.id}") + endedEarly = next.startMs; heldIdent = next + } + }) } else { SideEffect { window.onBack = { if (introPlayback?.showing == true) introPlayback.skip() else onClose() } } if (problem == null) ChannelTuningBackdrop(channel.number) { ProgrammeArtwork(session, channel, current) } @@ -158,8 +170,9 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC heldIdent?.let { held -> key(held.startMs) { val length = identLength(channel.number, held.startMs) - val startedLate = remember { (System.currentTimeMillis() + clockOffsetMs - (held.startMs - length)).coerceAtLeast(0) } - IdentOverlay(session, channel, held, length, startedLate) + val early = endedEarly == held.startMs + val startedLate = remember { if (early) 0L else (System.currentTimeMillis() + clockOffsetMs - (held.startMs - length)).coerceAtLeast(0) } + IdentOverlay(session, channel, held, length, startedLate, early) } } introPlayback?.let { IntroOverlay(it) } 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 eae0e37b..9fd2e688 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -33,7 +33,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.95.0") + next.setRequestProperty("User-Agent", "OrbitTV/0.95.1") 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/IdentTest.kt b/android/app/src/test/java/tv/orbit/classic/IdentTest.kt index 823373f6..27049353 100644 --- a/android/app/src/test/java/tv/orbit/classic/IdentTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/IdentTest.kt @@ -26,6 +26,15 @@ class IdentTest { assertEquals(IDENT_STING_MS, identLength(999)) } + @Test fun aFileStoppingWellBeforeItsSlotEndsCountsAsEndingEarly() { + // The 3 November Night Garden: booked to 19:28:06, its file stopped at 19:24:54. + val slotEnd = 26 * minute + assertTrue(finishedEarly(slotEnd - 192_000, slotEnd)) + // Running out in the last moments is just the credits, which the ident covers anyway. + assertFalse(finishedEarly(slotEnd - EARLY_END_GRACE_MS, slotEnd)) + assertFalse(finishedEarly(slotEnd + 1_000, slotEnd)) + } + @Test fun everyChannelHasItsOwnIdent() { SmartChannels.map { it.number }.filter { identVideo(it) == null }.let { assertEquals(emptyList(), it) } } diff --git a/docs/VERIFICATION-0.95.1.md b/docs/VERIFICATION-0.95.1.md new file mode 100644 index 00000000..3c8e90c5 --- /dev/null +++ b/docs/VERIFICATION-0.95.1.md @@ -0,0 +1,13 @@ +# Orbit TV 0.95.1: no black screen when a programme ends early + +A small fix of its own, approved by Paul on 3 November 2026. No scheduler, artwork or plan changes. + +**What happened:** on Tots (614) on 3 November, In the Night Garden S2 E37 was booked 19:02:01 to 19:28:06 from Emby's listed runtime (26:04). Its file stopped at 19:24:54, so the screen was black for just over three minutes until Clangers started on time at 19:28:06. Emby lists the episode about 3 minutes 10 seconds longer than the file actually plays, and Orbit had no handling for a programme ending before its slot. + +**The change:** when a scheduled programme's player reaches its end more than 3 seconds before the slot ends (`finishedEarly`, IdentTest), the channel's own ident plays from its start and holds its clean last frame, with NEXT AT 19:28 and the next title, until the next programme's booked start. Then the changeover is the usual one: the next programme is loaded ahead as before, and its first picture takes over from the held frame. With idents switched off, the same card shows the programme artwork and channel logo instead of the moving ident (Tots keeps its still as before). The early end is logged (`endedEarlyMs` in logcat tag OrbitSchedule and the playback notes) so other short files can be found. + +**Unchanged:** committed plans, the guide, the next programme's start time, preloading, the normal end-of-programme ident and hold. + +Files: Idents.kt (`finishedEarly`, `EARLY_END_GRACE_MS`, IdentOverlay's `early` caption), EmbyPlaybackDialog.kt (`onEndedEarly` on STATE_ENDED), SampleChannelScreens.kt (starts the ident early). 360 unit tests pass; lint has no errors. Not installed. + +**To check on the TV:** the next time a file runs short, the ident appears instead of black, holds with NEXT AT …, and the next programme starts on time. Logcat: `endedEarlyMs`.