0.99.15: hand-run playback test (Beerus), and the revised Afterburn premiere proposal
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m10s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m28s

Plays one episode in Orbit's own player via MainActivity's orbit_play_test extra, in a separate non-exported activity;
books nothing, reports nothing to Emby, ends by itself. Booking fingerprints identical to 0.99.14.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 15:01:22 +00:00
co-authored by Claude Opus 5.5
parent 0bd9a89bb4
commit fc6c8d3594
11 changed files with 375 additions and 68 deletions
+2
View File
@@ -6,5 +6,7 @@
<activity android:name=".MainActivity" android:exported="true" android:screenOrientation="landscape">
<intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>
</activity>
<!-- The hand-run playback test, opened only by MainActivity's orbit_play_test extra. -->
<activity android:name=".PlaybackTestActivity" android:exported="false" />
</application>
</manifest>
@@ -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.99.14\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.99.15\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -70,7 +70,11 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
/** Called when the programme's first picture is on screen, so anything held over the changeover can go. */
onFirstFrame: (() -> Unit)? = null,
/** Called when a scheduled programme's file runs out before its slot ends. */
onEndedEarly: (() -> Unit)? = null) {
onEndedEarly: (() -> Unit)? = null,
/** False for the hand-run playback test: nothing is reported to Emby, so it records no progress or resume point. */
reportPlayback: Boolean = true,
/** The playback test's own listener on the player, for its diagnostics. */
onPlayer: ((ExoPlayer) -> Unit)? = null) {
val context = LocalContext.current
val logoSetting = remember { OrbitSettings(context).channelLogo }
var failure by remember { mutableStateOf<String?>(null) }
@@ -105,6 +109,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
prepare(); playWhenReady = true
}
}
LaunchedEffect(player) { onPlayer?.invoke(player) }
fun textTracks() = player.currentTracks.groups.filter { it.type == C.TRACK_TYPE_TEXT && it.isSupported }
fun chooseSubtitle(index: Int?, tracks: List<Tracks.Group>) {
subtitleIndex = index
@@ -159,7 +164,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
val position = player.currentPosition
player.stop(); ready = false
stopReported = true
EmbyCleanup.run { session.report(plan, "Playing/Stopped", position, true) }
if (reportPlayback) EmbyCleanup.run { session.report(plan, "Playing/Stopped", position, true) }
}
}
lifecycle.addObserver(observer)
@@ -253,7 +258,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
player.removeListener(listener)
if (handedBack) return@onDispose
player.release()
if (!stopReported) EmbyCleanup.run { session.report(plan, "Playing/Stopped", position, true) }
if (!stopReported && reportPlayback) EmbyCleanup.run { session.report(plan, "Playing/Stopped", position, true) }
}
}
LaunchedEffect(player, ready) {
@@ -279,7 +284,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
}
}
LaunchedEffect(player, ready) {
if (ready && foreground) {
if (ready && foreground && reportPlayback) {
val startPosition = player.currentPosition; val startPaused = !player.isPlaying
withContext(Dispatchers.IO) { if (foreground) session.report(plan, "Playing", startPosition, startPaused) }
while (foreground) {
@@ -52,6 +52,10 @@ class MainActivity : ComponentActivity() {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (intent?.getBooleanExtra("orbit_intro_test", false) == true) IntroTrial.nextTune = true
intent?.getStringExtra("orbit_inspect_series")?.take(120)?.let { SeriesInspection.title = it }
// The hand-run playback test opens over Orbit, which stops in the background as it would for any other app, and comes back when it ends.
intent?.getStringExtra("orbit_play_test")?.takeIf(EmbyClient::validId)?.let { item ->
startActivity(android.content.Intent(this, PlaybackTestActivity::class.java).putExtra(PlaybackTestActivity.ITEM, item))
}
// One typeface everywhere, matching the channel logos.
setContent { MaterialTheme { CompositionLocalProvider(androidx.tv.material3.LocalTextStyle provides androidx.compose.ui.text.TextStyle(fontFamily = Barlow)) { OrbitApp() } } }
}
@@ -0,0 +1,139 @@
package tv.orbit.classic
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.sp
import androidx.media3.common.C
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.Tracks
import androidx.media3.common.text.CueGroup
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
/**
* The hand-run playback test (approved by Paul on 4 November 2026 for Dragon Ball Super: Beerus): one episode, by its
* Emby id, in Orbit's own player, opened with `--es orbit_play_test <id>` on MainActivity. English subtitles are chosen the
* way Orbit chooses them with its subtitles setting on. It books nothing and never touches the scheduler, plans, cursors or
* pools, reports nothing to Emby (so no progress or resume point is recorded there), and ends by itself after
* [TEST_MS], or on Back, returning to Orbit as it was. It logs formats, languages and counts only (tag OrbitPlayTest),
* never a title, path or address.
*/
class PlaybackTestActivity : ComponentActivity() {
companion object {
const val ITEM = "item"
const val TEST_MS = 3 * 60_000L
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
val item = intent?.getStringExtra(ITEM)?.takeIf(EmbyClient::validId) ?: run { finish(); return }
setContent { MaterialTheme { PlaybackTest(item) { finish() } } }
}
}
/** What the test saw, summed up at the end. Counts and formats only. */
internal class PlaybackTestRecord {
var ready = false
var firstFrame = false
var video = "none"
var audio = "none"
var subtitles = emptyList<String>()
var subtitleSelected = "none"
var cueUpdates = 0
var firstCueMs: Long? = null
var errors = 0
fun summary() = "playtest result ready=$ready firstFrame=$firstFrame video=$video audio=$audio subtitles=${subtitles.size}[${subtitles.joinToString(", ")}]" +
" subtitleSelected=$subtitleSelected cueUpdates=$cueUpdates firstCuePositionMs=${firstCueMs ?: "none"} errors=$errors"
}
/** A short, safe label: a language code or a format's MIME type (one slash at most), else "unknown". */
private val SafeLabel = Regex("""[A-Za-z0-9.+_-]{1,20}(/[A-Za-z0-9.+_-]{1,20})?""")
internal fun playTestLabel(value: String?) = value?.trim()?.takeIf(SafeLabel::matches) ?: "unknown"
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
@Composable
private fun PlaybackTest(itemId: String, done: () -> Unit) {
val context = LocalContext.current
var session by remember { mutableStateOf<EmbySampleSession?>(null) }
var plan by remember { mutableStateOf<EmbyPlaybackPlan?>(null) }
var problem by remember { mutableStateOf<String?>(null) }
val record = remember { PlaybackTestRecord() }
val subtitles = remember { mutableStateOf<String?>(SUBTITLES_BY_DEFAULT) }
val startedAt = remember { android.os.SystemClock.elapsedRealtime() }
var ended by remember { mutableStateOf(false) }
fun finish(reason: String) {
if (ended) return
ended = true
Log.i("OrbitPlayTest", record.summary() + " ended=$reason")
done()
}
LaunchedEffect(itemId) {
Log.i("OrbitPlayTest", "playtest start item=$itemId")
try {
withContext(Dispatchers.IO) {
val saved = RememberedConnectionStore.get(context).load() ?: throw EmbyCheckException("No saved connection.")
val active = EmbyClient(HttpsEmbyTransport(saved.identity.deviceId)).resume(saved)
session = active
val item = SampleItem("Playback test", "Episode", null, "", itemId)
active.rememberScheduledItems(listOf(item))
plan = active.prepare(item)
}
} catch (failure: Exception) {
Log.w("OrbitPlayTest", "playtest failed=${failure.javaClass.simpleName} status=${(failure as? EmbyCheckException)?.httpStatus}")
problem = "The playback test couldn't start."
delay(5_000)
finish("failed")
}
}
// The test ends by itself, whatever happens.
LaunchedEffect(plan) { if (plan != null) { delay(PlaybackTestActivity.TEST_MS); finish("time") } }
// The test's own session ends without signing out, so Orbit's saved connection carries on.
DisposableEffect(Unit) { onDispose { session?.let { active -> EmbyCleanup.run { active.detach() } } } }
Box(Modifier.fillMaxSize().background(Color.Black), contentAlignment = Alignment.Center) {
val ready = plan
val active = session
if (ready != null && active != null) {
EmbyPlaybackDialog(active, ready, onClose = { finish("back") }, subtitlePreference = subtitles, announce = false, reportPlayback = false,
onPlayer = { player ->
player.addListener(object : Player.Listener {
override fun onPlaybackStateChanged(state: Int) {
if (state == Player.STATE_READY && !record.ready) { record.ready = true; Log.i("OrbitPlayTest", "playtest readyMs=${android.os.SystemClock.elapsedRealtime() - startedAt}") }
if (state == Player.STATE_ENDED) finish("ended")
}
override fun onRenderedFirstFrame() { record.firstFrame = true }
override fun onPlayerError(error: PlaybackException) { record.errors++; Log.w("OrbitPlayTest", "playtest error=${error.errorCodeName}") }
override fun onTracksChanged(tracks: Tracks) {
fun selected(type: Int) = tracks.groups.filter { it.type == type && it.isSelected }.mapNotNull { g -> (0 until g.length).firstOrNull(g::isTrackSelected)?.let(g::getTrackFormat) }.firstOrNull()
selected(C.TRACK_TYPE_VIDEO)?.let { record.video = "${playTestLabel(it.sampleMimeType)} ${it.width}x${it.height}" }
selected(C.TRACK_TYPE_AUDIO)?.let { record.audio = "${playTestLabel(it.sampleMimeType)} ${playTestLabel(it.language)} ${it.channelCount}ch" }
val text = tracks.groups.filter { it.type == C.TRACK_TYPE_TEXT }
record.subtitles = text.map { g -> g.getTrackFormat(0).let { "${playTestLabel(it.sampleMimeType ?: it.codecs)} ${playTestLabel(it.language)}" + (if (g.isSupported) "" else " unsupported") + (if (g.isSelected) " selected" else "") } }
record.subtitleSelected = selected(C.TRACK_TYPE_TEXT)?.let { playTestLabel(it.language) } ?: "none"
Log.i("OrbitPlayTest", "playtest tracks video=${record.video} audio=${record.audio} subtitles=${record.subtitles.joinToString(", ")}")
}
override fun onCues(cueGroup: CueGroup) {
if (cueGroup.cues.isEmpty()) return
record.cueUpdates++
if (record.firstCueMs == null) { record.firstCueMs = player.currentPosition; Log.i("OrbitPlayTest", "playtest firstCuePositionMs=${record.firstCueMs}") }
}
})
})
} else Text(problem ?: "Playback test…", color = Muted, fontSize = 16.sp)
}
}
@@ -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.99.14")
next.setRequestProperty("User-Agent", "OrbitTV/0.99.15")
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()) {
@@ -0,0 +1,30 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Test
class PlaybackTestTest {
@Test fun labelsAreShortAndSafe() {
assertEquals("text/x-ssa", playTestLabel("text/x-ssa"))
assertEquals("jpn", playTestLabel("jpn"))
assertEquals("unknown", playTestLabel(null))
for (hostile in listOf("https://host/stream?api_key=SECRET", "/mnt/media/Beerus.mkv", "media/anime/Beerus.mkv", "Japanese (Crunchyroll)", "a".repeat(41))) assertEquals("unknown", playTestLabel(hostile))
}
@Test fun theSummaryHoldsFormatsAndCountsOnly() {
val record = PlaybackTestRecord().apply {
ready = true; firstFrame = true; video = "video/avc 1920x1080"; audio = "audio/mp4a-latm jpn 2ch"
subtitles = listOf("text/x-ssa eng selected", "text/x-ssa por"); subtitleSelected = "eng"; cueUpdates = 41; firstCueMs = 12_345
}
assertEquals("playtest result ready=true firstFrame=true video=video/avc 1920x1080 audio=audio/mp4a-latm jpn 2ch subtitles=2[text/x-ssa eng selected, text/x-ssa por]" +
" subtitleSelected=eng cueUpdates=41 firstCuePositionMs=12345 errors=0", record.summary())
assertFalse(PlaybackTestRecord().summary().contains("null"))
}
@Test fun englishIsChosenTheWayOrbitChoosesIt() {
// The test asks for subtitles as Orbit's setting does: English where there is some, whatever the track order.
assertEquals(2, subtitleFor(SUBTITLES_BY_DEFAULT, listOf("por", "spa", "eng")))
assertEquals(null, subtitleFor(null, listOf("eng")))
}
}