I have a function:
private fun WebView.initVideo(video: String) {
WebViewVideoPlayerUtils.addCookie(video, this)
with(settings) {
javaScriptEnabled = true
domStorageEnabled = true
cacheMode = WebSettings.LOAD_NO_CACHE
builtInZoomControls = true
allowFileAccess = true
loadWithOverviewMode = true
useWideViewPort = true
}
loadDataWithBaseURL(
null,
video,
"text/html",
"utf-8",
null
)
}
And it worked fine. But after updating project it's not playing video. Just shows String
<iframe width=“853” height=“480” src=“https://www.youtube.com/embed/_iATsZKqYF0" frameborder=“0” allow=“accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture” allowfullscreen></iframe>
How could I Fix it?
P.S. AndroidManifest.xml contains needed permission and
android:hardwareAccelerated="true" android:usesCleartextTraffic="true"
P.P.S: Using logs I find out that parameter video comes as a String:
<iframe width="853" height="480" src="https://www.youtube.com/embed/_iATsZKqYF0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
And it works fine if I manually change it to
"<iframe width=\"853\" height=\"480\" src=\"" + "https://www.youtube.com/embed/_iATsZKqYF0" + "\" frameborder=\"0\" allow=\"accelerometer;autoplay;encrypted-media;gyroscope;picture-in-picture\" allowfullscreen/>"
As if Android can't parse it I have a lot of screens using this strings for playing video. So how could I resolve this problem in one place?
It was just the encoding mistake on the server side. Adding the line
val parsedVideo = Html.fromHtml(video, Html.FROM_HTML_MODE_LEGACY).toString()
resolved the issue.