【问题标题】:Android WebView crashes when loading HLS playlist加载 HLS 播放列表时 Android WebView 崩溃
【发布时间】:2019-04-17 16:47:41
【问题描述】:

我们编写了一个嵌入 web 视图的大型 Kotlin 应用程序。就在今天,我们发现一些 URL 嵌入了带有 m3u8 播放列表 URL 的 <VIDEO> 标签。 页面一加载,我们就会遇到很多错误,如果我们触摸播放图标,什么也不会发生。有时甚至应用程序也会崩溃。

为了找出问题,我们编写了一个非常简单的应用程序,只有一个 WebView,我们尝试加载 Apple 示例页面: https://developer.apple.com/streaming/examples/basic-stream-osx-ios4-3.html

该应用在多个物理设备上进行了测试。

这是相关的 gradle 部分


android {
    compileSdkVersion 28
    defaultConfig { 
        minSdkVersion 24
        targetSdkVersion 28 

我们在清单中添加了适当的权限

        <uses-permission android:name="android.permission.INTERNET"/>

这是我们的 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")
    }
}

Apple 的页面加载正常(或者看起来,我们可以在屏幕上看到它)但是我们在 LogCat 中遇到了很多错误,我们无法播放视频。

这些是日志中的一些错误。当然,我们的项目中没有res/raw/empty.wav 文件。它是通过 AndroidStudio 向导从头开始创建的。

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

知道我们可以做些什么来在 WebView 中加载视频吗? 非常感谢。

【问题讨论】:

    标签: android kotlin webview http-live-streaming


    【解决方案1】:

    启用 appcache 后,它对我有用。

    testWebView.settings.setAppCacheEnabled(true)
            testWebView.loadUrl("https://developer.apple.com/streaming/examples/basic-stream-osx-ios4-3.html")
    

    【讨论】:

    • 这似乎可以解决问题,至少视频加载并开始。目前速度很慢,但我们希望这是网络问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 2017-04-28
    • 2023-03-07
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多