HTML5-视频在 Webview 中因 "Surface Texture is abondoned" 崩溃

HTML5-Video crashes with "Surface Texture is abondoned" in Webview

我在 Android Studio 中创建了一个 webview,并打开了 WebChromeClient 和硬件加速来播放自定义播放列表中的 HTML5 视频。

几天来一切正常,但是当我离开 activity,即打开第二个,然后返回到网络视图时,大部分视频都会在一段时间后崩溃。声音还在,但是屏幕变黑了。

同时logcatreturns"E/SurfaceTexture﹕ [unnamed-6010-15498] updateTexImage: SurfaceTexture is abandoned!"。

我现在的问题是:这是硬件问题吗?如果是 - 为什么我第一次启动 webview 时没有出现?

AndroidManifest.xml:

<application
  android:name=".App"
  android:allowBackup="true"
  android:hardwareAccelerated="true"
  android:icon="@drawable/ic_launcher"
  android:label="@string/General_Appinfo_Label"
  android:theme="@style/AppTheme" >

<activity
  android:name=".Webview"
  android:configChanges="orientation|screenSize"
  android:label="@string/General_Appinfo_Label"
  android:noHistory="true"
  android:hardwareAccelerated="true"
  android:theme="@android:style/Theme.NoTitleBar" >
  <intent-filter>
   <action android:name="de.neolino.smartesign.Webview" />
   <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

Webview.class(节选):

Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
App.webview = new WebView(this);
WebChromeClient chromeClient = new WebChromeClient();
App.webview.setWebChromeClient(chromeClient);
windowContext = getWindow(); // for later use
decorViewWebview = windowContext.getDecorView();
final int uiOptions =(View.SYSTEM_UI_FLAG_FULLSCREEN
                     | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                     | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                     | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                     | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                     | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
decorViewWebview.setSystemUiVisibility(uiOptions);
WebSettings webSettings = App.webview.getSettings();
webSettings.setAppCacheEnabled(false);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
App.webview.clearCache(true);
webSettings.setAllowFileAccess(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setSaveFormData(true);
setContentView(App.webview);    
webSettings.setMediaPlaybackRequiresUserGesture(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
App.webview.loadUrl(Pref.getString("SettingsWebviewTargetDialog"));

Logcat:

02-16 10:02:50.707    2678-9854/? I/OMXPlayer﹕ Stop Player.
02-16 10:02:50.757    2678-9854/? I/vpu-lib﹕ <gpu> free handle: 0x4c932b78, paddr: 0x4762b000, vaddr: 0x44f01000
02-16 10:02:50.757    2678-9854/? I/vpu-lib﹕ <gpu> free handle: 0x4c932b50, paddr: 0x48210000, vaddr: 0x45ae6000
02-16 10:02:50.757    2678-9854/? I/vpu-lib﹕ <gpu> free handle: 0x4c93da30, paddr: 0x48710000, vaddr: 0x45fe6000
02-16 10:02:50.777    2678-2939/? I/OMXPlayer﹕ Loading content: sharedfd://24:0:27399381:0
02-16 10:02:50.777    2678-2939/? I/OMXPlayer﹕ LEVEL: 1 FUNCTION: MediaTypeInspect LINE: 1656
02-16 10:02:50.777    2678-2939/? I/OMXPlayer﹕ Can't inspect media content type by subfix.
02-16 10:02:50.807   2678-20974/? I/OMXPlayer﹕ LEVEL: 1 FUNCTION: prepare LINE: 422
02-16 10:02:50.807   2678-20974/? I/OMXPlayer﹕ failed to open file: /data/system/audio_pass_through_pref.
02-16 10:02:50.807   2678-20974/? I/OMXPlayer﹕ Can't open library: lib_aacplusd_wrap_arm12_elinux_android.so
02-16 10:02:50.807   2678-20974/? I/OMXPlayer﹕ Cannot load library: load_library(linker.cpp:745): library "lib_aacplusd_wrap_arm12_elinux_android.so" not found
02-16 10:02:50.807    6010-6010/de.neolino.smartesign E/SurfaceTexture﹕ [unnamed-6010-15654] updateTexImage: SurfaceTexture is abandoned!
02-16 10:02:50.837   2678-20974/? I/vpu-lib﹕ Product Info: i.MX6Q/D/S
02-16 10:02:50.847   2678-20974/? I/OMXPlayer﹕ VideoRender role: video_render.surface
02-16 10:02:50.847   2678-20975/? I/OMXPlayer﹕ nPreCacheSize = 913312
02-16 10:02:50.877   2678-20974/? I/vpu-lib﹕ <gpu> alloc handle: 0x4c15fdf0, paddr: 0x47232000, vaddr: 0x44b08000
02-16 10:02:50.887   2678-20974/? I/vpu-lib﹕ <gpu> alloc handle: 0x4c15fe68, paddr: 0x47385000, vaddr: 0x44c5b000
02-16 10:02:50.887   2678-20974/? I/vpu-lib﹕ <gpu> alloc handle: 0x4c15ff10, paddr: 0x474d8000, vaddr: 0x44dae000
02-16 10:02:50.887   2678-20978/? I/vpu-lib﹕ <gpu> alloc handle: 0x4c15ff68, paddr: 0x48210000, vaddr: 0x45ae6000
02-16 10:02:50.887   2678-20978/? I/vpu-lib﹕ <gpu> alloc handle: 0x4c15ff90, paddr: 0x4762b000, vaddr: 0x44f01000
02-16 10:02:50.887   2678-20978/? I/vpu-lib﹕ bitstreamMode 1, chromaInterleave 1, mapType 0, tiled2LinearEnable 0
02-16 10:02:50.887   2678-20978/? W/vpu-lib﹕ VPU iram is less than needed, some parts don't use iram
02-16 10:02:50.897   2678-20974/? I/vpu-lib﹕ <gpu> free handle: 0x4c15fdf0, paddr: 0x47232000, vaddr: 0x44b08000
02-16 10:02:50.897   2678-20974/? I/vpu-lib﹕ <gpu> free handle: 0x4c15fe68, paddr: 0x47385000, vaddr: 0x44c5b000
02-16 10:02:50.897   2678-20974/? I/vpu-lib﹕ <gpu> free handle: 0x4c15ff10, paddr: 0x474d8000, vaddr: 0x44dae000
02-16 10:02:50.927   2678-20978/? I/vpu-lib﹕ <gpu> alloc handle: 0x4c768570, paddr: 0x48710000, vaddr: 0x45fe6000
02-16 10:02:50.927   2678-20974/? I/OMXPlayer﹕ Seek to 0
02-16 10:02:50.947    2678-9855/? I/OMXPlayer﹕ start player.

就我而言,解决方案只是时间问题。

我在后台使用 IntentService 更改了本地数据。之后我关闭了 Webview 并再次启动它。但是 Surface Texture 似乎没有足够快地意识到这一点,或者根本没有重建。

一个简单的 webview.reload() 响应。 webview.loadUrl() 在启动 Webview 的新实例的情况下成功了。

从 Android 4.4 开始,您必须在运行 Webview 的同一线程中执行此操作。要从 Webview 的线程外部执行此操作 - 即函数 - 您必须构建一个全局 Webview 对象并调用它像这样:

App.webview.post(new Runnable() {
    @Override
    public void run() {
      App.webview.loadUrl("file://" + someLocalFile.getAbsolutePath());
    }
});