feat(media): subtitles that travel with the film — CLI, browser <track>, ExoPlayer
`shade media put Film.mkv` seals Film.srt / Film.no.srt / Film.en.vtt found beside it and carries their grants in the film's sealed meta (extra["shade.subtitles"]), so they follow the film alone or in an album and the relay sees unrelated objects. /watch/ adds them as <track>s (SRT to VTT, labels in the viewer's language, the viewer's language on, one at a time); `media get` writes them back; Android opens them with ShadeMedia.openFilm and gives them to ExoPlayer as side-loaded tracks (ShadeMediaDataSource now resolves readers by URI). Verified: 76 TS tests; Chromium nb-NO shows the Norwegian track only, en-US the English one; film + subtitles round-trip bit-identical; Robolectric ExoPlayer sees both text tracks with the Norwegian one default; a shared vector checks the meta field in Kotlin (82/0). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,9 +21,9 @@ import androidx.media3.ui.PlayerView
|
||||
import no.zyon.shade.media.LiveContent
|
||||
import no.zyon.shade.media.LiveGrant
|
||||
import no.zyon.shade.media.MediaGrant
|
||||
import no.zyon.shade.media.MediaReader
|
||||
import no.zyon.shade.media.ReceivedFrame
|
||||
import no.zyon.shade.media.android.LiveWatcher
|
||||
import no.zyon.shade.media.android.ShadeFilm
|
||||
import no.zyon.shade.media.android.ShadeMedia
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.concurrent.Executors
|
||||
class PlayerActivity : Activity() {
|
||||
private val io = Executors.newSingleThreadExecutor()
|
||||
private var player: ExoPlayer? = null
|
||||
private var reader: MediaReader? = null
|
||||
private var film: ShadeFilm? = null
|
||||
private var watcher: LiveWatcher? = null
|
||||
private lateinit var status: TextView
|
||||
private lateinit var view: PlayerView
|
||||
@@ -116,7 +116,7 @@ class PlayerActivity : Activity() {
|
||||
is MediaGrant -> {
|
||||
status.text = "Opening…"
|
||||
io.execute {
|
||||
val opened = runCatching { grant.open() }
|
||||
val opened = runCatching { ShadeMedia.openFilm(grant) }
|
||||
runOnUiThread {
|
||||
opened.fold(
|
||||
onSuccess = { start(it) },
|
||||
@@ -187,13 +187,14 @@ class PlayerActivity : Activity() {
|
||||
return p
|
||||
}
|
||||
|
||||
private fun start(r: MediaReader) {
|
||||
reader = r
|
||||
private fun start(f: ShadeFilm) {
|
||||
film = f
|
||||
showPlayer(true)
|
||||
val p = newPlayer()
|
||||
val name = r.meta.name ?: "sealed file"
|
||||
status.text = "$name · ${r.meta.mime ?: "?"} · ${r.size / 1024} KiB · end-to-end encrypted"
|
||||
p.setMediaSource(ShadeMedia.mediaSource(r))
|
||||
val meta = f.reader.meta
|
||||
val subs = if (f.subtitles.isEmpty()) "" else " · ${f.subtitles.size} subtitle track(s)"
|
||||
status.text = "${meta.name ?: "sealed file"} · ${meta.mime ?: "?"} · ${f.reader.size / 1024} KiB$subs · end-to-end encrypted"
|
||||
p.setMediaSource(ShadeMedia.mediaSource(f))
|
||||
p.prepare()
|
||||
p.play()
|
||||
}
|
||||
@@ -204,8 +205,8 @@ class PlayerActivity : Activity() {
|
||||
view.player = null
|
||||
player?.release()
|
||||
player = null
|
||||
reader?.close()
|
||||
reader = null
|
||||
film?.close()
|
||||
film = null
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
|
||||
Reference in New Issue
Block a user