我遇到以下问题:我正在使用WebView
在我的应用中显示一些内容。有时会有一个视频嵌入到此WebView
中显示的内容中。问题是点击"播放"后,视频开始播放,但没有图像可见 - 只播放声音。在开始播放视频之前 - 会显示正确的缩略图。在LogCat中,我看到以下错误消息:
06-26 16:51:21.449 25222-25222/com.package.app V/MediaPlayer-JNI﹕ native_setup
06-26 16:51:21.449 25222-25222/com.package.app V/MediaPlayer﹕ constructor
06-26 16:51:21.459 25222-25222/com.package.app V/MediaPlayer﹕ setListener
06-26 16:51:21.459 25222-25222/com.package.app I/MediaPlayer﹕ path is null
06-26 16:51:21.479 25222-25222/com.package.app D/MediaPlayer﹕ setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: http://example.com/linktovideo.mp4
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1052)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:834)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:987)
at com.android.org.chromium.media.MediaPlayerBridge.setDataSource(MediaPlayerBridge.java:117)
at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
06-26 16:51:21.479 25222-25222/com.package.app D/MediaPlayer﹕ Couldn't open file on client side, trying server side
在Chrome for Android网络浏览器中正确显示相同的视频。
代码我用来显示我的WebView
:
mWebView = (WebView) v.findViewById(R.id.details_web_view);
mWebView.getSettings().setJavaScriptEnabled(false);
mWebView.setBackgroundColor(0x00000000);
mWebView.setWebViewClient(new CustomWebViewClient());
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
CustomWebViewClient:
private class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http://")) {
getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
AnalyticsHandler.sendAction(getActivity(), AnalyticsHandler.ACTION_CLICKED_ON_URL_IN_ARTICLE, url);
}
return true;
}
}
答案 0 :(得分:1)
将此代码添加到您的网页浏览中
WebSettings.setJavaScriptEnabled(true);
答案 1 :(得分:1)
尝试
mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);