fix(android): YouTube error 152 - embed under a third-party domain, not youtube.com

The player loaded the YouTube embed via loadDataWithBaseURL with base
https://www.youtube.com, so the embedding page claimed to BE youtube.com hosting
a youtube.com iframe. YouTube rejects that as an invalid embed context -> 'This
video is unavailable / Error 152 - 4' for every video (reproduced on a Pixel 10
/ Android 16 emulator with multiple known-embeddable videos).

Load the embed under a real third-party domain (EMBED_BASE = the product domain)
so the referrer is a legitimate embedding site. The iframe still points at
youtube.com/embed. Verified: video now plays. (The earlier base=youtube.com was
the Error 153 fix; this supersedes it - a normal domain referrer fixes 153 too.)
This commit is contained in:
ScreenTinker 2026-06-09 15:36:24 -05:00
parent b88150c115
commit 4572963175
3 changed files with 8 additions and 2 deletions

View file

@ -59,7 +59,7 @@ class MediaPlayerManager(
setBackgroundColor(android.graphics.Color.BLACK)
// Load via an embed wrapper with a valid youtube.com origin (Error 153 fix).
val html = com.remotedisplay.player.util.WebViewSupport.youtubeEmbedHtml(embedUrl)
if (html != null) loadDataWithBaseURL(com.remotedisplay.player.util.WebViewSupport.YT_BASE, html, "text/html", "UTF-8", null)
if (html != null) loadDataWithBaseURL(com.remotedisplay.player.util.WebViewSupport.EMBED_BASE, html, "text/html", "UTF-8", null)
else loadUrl(embedUrl)
}
}

View file

@ -159,7 +159,7 @@ class ZoneManager(
mimeType == "video/youtube" && !remoteUrl.isNullOrEmpty() -> {
val webView = createWebView()
val html = com.remotedisplay.player.util.WebViewSupport.youtubeEmbedHtml(remoteUrl)
if (html != null) webView.loadDataWithBaseURL(com.remotedisplay.player.util.WebViewSupport.YT_BASE, html, "text/html", "UTF-8", null)
if (html != null) webView.loadDataWithBaseURL(com.remotedisplay.player.util.WebViewSupport.EMBED_BASE, html, "text/html", "UTF-8", null)
else webView.loadUrl(remoteUrl)
webView.layoutParams = params
container.addView(webView); zoneViews[zone.id] = webView

View file

@ -23,6 +23,12 @@ import android.webkit.WebViewClient
object WebViewSupport {
const val YT_BASE = "https://www.youtube.com"
// Base URL the embed page is loaded under (its referrer to YouTube). It must be
// a normal embedding site, NOT youtube.com itself — a page claiming to be
// youtube.com embedding a youtube.com iframe is rejected as an invalid embed
// context ("This video is unavailable / Error 152"). A real third-party domain
// is what legitimate embeds use.
const val EMBED_BASE = "https://screentinker.com"
fun configure(webView: WebView, tag: String) {
webView.settings.apply {