Android WebView 播放視訊(youku,youtube等)的設定
阿新 • • 發佈:2019-02-11
1,在manifest中設定Activity的hardwareAccelerated為true
android:hardwareAccelerated="true"
2,在layout中設定WebView的layerType為hardware
android:layerType="hardware"
3,在程式碼中設定
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setPluginState(PluginState.ON); webView.setWebChromeClient(new WebChromeClient());
4,Activity切換時視訊還在繼續播放,需作以下設定
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { webView.loadData("", "text/html; charset=UTF-8", null); MainDetailView.this.finish(); } } @Override public void onPause() { super.onPause(); webView.onPause(); } @Override public void onResume() { super.onResume(); webView.onResume(); }