feat(player): render Android video natively behind a transparent webview (DR-150, DR-151, DR-152)
Rust already reported `use_html5_element: false` on Android, but two frontend overrides threw that answer away, so ExoPlayer's video path had never actually run. Both are lifted behind an `experimentalNativeVideo` opt-in (default off). The flag is a suppressor, never a promoter: off forces HTML5 even where Rust says native, so an in-progress spike cannot ship as the default, but it can never select native where Rust reported HTML5 — Linux cannot composite behind WebKitGTK, and promoting there would be a black screen. Two blockers the spec did not anticipate, both in code assumed to be merely unreachable rather than broken: - `JellyTauPlayer.setActivity()` had zero callers, so `currentActivity` was always null and `autoAttachSurface()` bailed. The SurfaceView was created and wired to ExoPlayer but never added to the view hierarchy — video would have decoded to a surface that was never on screen, whatever the webview did. This also revives PiP on the video path, which gated on the same flag. - `createAdapter()` was not the real gate; it is never called in production. The actual override was in VideoPlayer.svelte, which forced HTML5 and stopped the native backend `player_play_item` had just started. Both sites now route through `createAdapter()`. Compositing needs two independent opaque layers cleared, not one. Clearing only the page leaves the WebView widget opaque — audio over a black picture, exactly the symptom the old INTERIM comment described. `videoSurface.ts` toggles both: the widget background and window drawable from Kotlin, the page backgrounds via a `data-native-video` attribute keyed by app.css. Transparency lives in `tauri.android.conf.json` so Linux keeps an opaque window, and is scoped to the playback session so the launcher never shows through the rest of the app. Phase 3's rect plumbing turned out to be unnecessary: video is fullscreen on the player route, and `fitSurfaceToScreen()` already letterboxes and re-fits on rotation. The mini-player transition remains unverified on device. Also removes the `navigator.userAgent` sniffing in webviewAudio.ts, which was a second copy of the Rust cfg gate free to drift from it. `player_get_capabilities` now reports `usesWebviewAudio` and `supportsNativeVideo` from those same gates. Tests: adapter selection covers the full matrix, including the regression guard that the flag off beats Rust. Written first and confirmed failing (2 of 7) before the fix. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,20 @@ class MainActivity : TauriActivity() {
|
||||
// so on devices with a tall opaque 3-button bar. (UR-066)
|
||||
WindowInsetsBridge.install(this)
|
||||
|
||||
// Hand the player an Activity reference so it can attach its video
|
||||
// SurfaceView to the content view behind the WebView.
|
||||
//
|
||||
// Without this, JellyTauPlayer.currentActivity stays null forever and
|
||||
// autoAttachSurface() logs "Cannot attach surface - no Activity reference"
|
||||
// and returns — so the SurfaceView is created, wired to ExoPlayer, and then
|
||||
// never added to the view hierarchy. Native video decoded to a surface that
|
||||
// was never on screen. setActivity() stores into a companion-object
|
||||
// WeakReference, so calling it here (before Rust initializes the player over
|
||||
// JNI) is safe and is the case it was written for.
|
||||
//
|
||||
// TRACES: UR-003, UR-041 | DR-151
|
||||
com.dtourolle.jellytau.player.JellyTauPlayer.setActivity(this)
|
||||
|
||||
// Configure WebView for media playback after Tauri initialization
|
||||
handler.postDelayed({
|
||||
configureWebViewForMedia()
|
||||
@@ -271,6 +285,46 @@ class MainActivity : TauriActivity() {
|
||||
}, "AndroidNetworkType")
|
||||
android.util.Log.d("MainActivity", "JavaScript interface 'AndroidNetworkType' added")
|
||||
|
||||
// Native video compositing: let the frontend make the WebView transparent
|
||||
// so the ExoPlayer SurfaceView behind it is visible (UR-003, UR-004).
|
||||
//
|
||||
// Toggled rather than set once because a transparent WebView is only
|
||||
// correct while a native video is on screen — every other screen needs its
|
||||
// opaque background, and leaving the window transparent shows the
|
||||
// launcher/wallpaper through the app.
|
||||
//
|
||||
// The CSS in app.css clears the *web* layer's backgrounds; this clears the
|
||||
// WebView widget's own background, which CSS cannot reach. Both are
|
||||
// required — an opaque WebView hides the surface no matter what the page
|
||||
// paints.
|
||||
//
|
||||
// TRACES: UR-003, UR-004 | DR-150
|
||||
webView.addJavascriptInterface(object : Any() {
|
||||
/** Make the WebView background transparent (true) or opaque (false). */
|
||||
@JavascriptInterface
|
||||
fun setTransparent(transparent: Boolean) {
|
||||
handler.post {
|
||||
val color = if (transparent) {
|
||||
android.graphics.Color.TRANSPARENT
|
||||
} else {
|
||||
android.graphics.Color.BLACK
|
||||
}
|
||||
mediaWebView?.setBackgroundColor(color)
|
||||
// The WebView's window/surface must also stop painting opaque, or a
|
||||
// hardware-accelerated WebView still composites its own background.
|
||||
window.setBackgroundDrawable(
|
||||
android.graphics.drawable.ColorDrawable(color)
|
||||
)
|
||||
android.util.Log.d("MainActivity", "WebView transparent = $transparent")
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether native-video compositing is available on this platform. */
|
||||
@JavascriptInterface
|
||||
fun isSupported(): Boolean = true
|
||||
}, "AndroidVideoSurface")
|
||||
android.util.Log.d("MainActivity", "JavaScript interface 'AndroidVideoSurface' added")
|
||||
|
||||
// Window insets (safe areas). The push path above races the page load, so
|
||||
// the frontend pulls the current values on mount through this bridge.
|
||||
webView.addJavascriptInterface(WindowInsetsBridge.jsInterface(), "AndroidInsets")
|
||||
|
||||
Reference in New Issue
Block a user