We have written a big Kotlin app that embeds a webview. Just today we have discovered that some of the URLs embeds a <VIDEO>
tag with a m3u8
playlist url.
As soon as the page load, we got plenty of errors and if we touch the play icon nothing happens. Sometimes even the app crashes.
To single out the problem we have written a very simple app with just a WebView, and we try to load the Apple sample page:
https://developer.apple.com/streaming/examples/basic-stream-osx-ios4-3.html
The app is tested on several physical devices.
This is the relevant gradle section
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 24
targetSdkVersion 28
We have added proper permissions in manifest
<uses-permission android:name="android.permission.INTERNET"/>
and this is our MainActivity
package iakta.it.webviewtest
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
testWebView.loadUrl("https://developer.apple.com/streaming/examples/basic-stream-osx-ios4-3.html")
}
}
the Apple's page loads ok (or so it seems, we can see it on screen) but we got plenty of errors in LogCat and we are unable to play the video.
These are some of the errors in the log. And of course we don't have a res/raw/empty.wav
file in our project. It was just created from scratch via the AndroidStudio wizard.
2019-04-17 18:34:45.168 9326-9326/iakta.it.webviewtest E/cr_crMediaCrashListener: Exception while creating the watchdog player.
android.content.res.Resources$NotFoundException: File res/raw/empty.wav from drawable resource ID #0x2120000
at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:316)
at android.content.res.Resources.openRawResourceFd(Resources.java:1293)
at android.media.MediaPlayer.create(MediaPlayer.java:967)
at android.media.MediaPlayer.create(MediaPlayer.java:950)
at org.chromium.media.MediaServerCrashListener.startListening(PG:13)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.openNonAssetFdNative(Native Method)
at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:487)
at android.content.res.ResourcesImpl.openRawResourceFd(ResourcesImpl.java:314)
at android.content.res.Resources.openRawResourceFd(Resources.java:1293)
at android.media.MediaPlayer.create(MediaPlayer.java:967)
at android.media.MediaPlayer.create(MediaPlayer.java:950)
at org.chromium.media.MediaServerCrashListener.startListening(PG:13)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
2019-04-17 18:34:45.168 9326-9326/iakta.it.webviewtest E/cr_crMediaCrashListener: Unable to create watchdog player, treating it as server crash.
2019-04-17 18:34:45.197 9326-9326/iakta.it.webviewtest W/MediaPlayer: Couldn't open https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8: java.io.FileNotFoundException: No content provider: https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8
2019-04-17 18:34:45.198 9326-9326/iakta.it.webviewtest V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@dbda0d3): Cookies: null
2019-04-17 18:34:45.210 9326-9417/iakta.it.webviewtest V/MediaHTTPService: makeHTTPConnection: CookieManager created: java.net.CookieManager@6eff410
2019-04-17 18:34:45.210 9326-9417/iakta.it.webviewtest V/MediaHTTPService: makeHTTPConnection(android.media.MediaHTTPService@dbda0d3): cookieHandler: java.net.CookieManager@6eff410 Cookies: null
2019-04-17 18:34:46.987 9326-9343/iakta.it.webviewtest I/zygote64: Waiting for a blocking GC ProfileSaver
Any idea as to what we might do to load the video in the WebView? Thanks a lot.
After enabling appcache its working for me.
testWebView.settings.setAppCacheEnabled(true)
testWebView.loadUrl("https://developer.apple.com/streaming/examples/basic-stream-osx-ios4-3.html")