0.95.1: when a programme's file ends before its slot, play and hold the channel ident (NEXT AT …) instead of a black screen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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 }
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<String?>(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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<SampleBroadcast?>(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<Long?>(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) }
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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<Int>(), it) }
|
||||
}
|
||||
|
||||
@@ -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`.
|
||||
Reference in New Issue
Block a user