如何在WebView中播放离线视频(来自SD卡)

时间:2018-08-29 13:49:52

标签: android html5 video android-webview offline-mode

我能够通过以下代码在线观看视频,但无法在webview中离线观看视频(SD卡/内部存储)。

    String text = "<h4>Write the type of reaction in the following</h4><h4>&nbsp; 1) Reaction between an acid and base&nbsp; &nbsp; &nbsp;</h4><h4> &nbsp;2) Rusting of iron&nbsp; &nbsp;</h4>\n" +
            "<video width=\"620\" controls>\n" +
            "  <source\n" +
            "    src=\"/storage/3232-6333/demo/test.mp4\"\n" +
            "    type=\"video/mp4\">\n" +
            "  Your browser doesn't support HTML5 video tag.\n" +
            "</video>";

    webViewText = text;

    WebSettings webSettings = webView.getSettings();
    webSettings.setAllowFileAccessFromFileURLs(true);

//webSettings.setPluginState(WebSettings.PluginState.ON_DEMAND);
//webSettings.setJavaScriptEnabled(true);

    webSettings.setJavaScriptEnabled(true);
    webSettings.setMediaPlaybackRequiresUserGesture(false);

//webSettings.setAppCacheMaxSize(25 * 1024 * 1024); // 25MB
//webSettings.setAppCachePath(mContext.getCacheDir().getAbsolutePath());
//webSettings.setAllowFileAccess(true);
//webSettings.setAppCacheEnabled(true);
//webSettings.setJavaScriptEnabled(true);
// load online by default
//webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); 

  //if (!AndroidUtils.isNetWorkOnline(mContext)) { // loading offline
   //webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  //}

  webView.setWebChromeClient(new WebChromeClient());

webView.loadDataWithBaseURL("", webViewText, "text/html", "utf-8", "");

我也尝试使用上述所有注释方法来设置webview设置,但不起作用。

我收到以下日志消息

08-29 18:34:36.551 28771-28888/com.gopal.webviewdemo W/VideoCapabilities: Unrecognized profile/level 0/2 for video/mpeg2
08-29 18:34:36.551 28771-28888/com.gopal.webviewdemo W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2
08-29 18:34:36.591 28771-28888/com.gopal.webviewdemo I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
08-29 18:34:36.846 28771-28925/com.gopal.webviewdemo W/cr_CrashFileManager: /data/user/0/cpr.name.videoenabledwebview/cache/WebView/Crash Reports does not exist or is not a directory
08-29 18:34:36.849 28771-28771/com.gopal.webviewdemo I/chromium: [INFO:CONSOLE(0)] "The deviceorientation event is deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins for more details.", source:  (0)

任何帮助都非常有帮助。在此先感谢您,我的英语很抱歉。

0 个答案:

没有答案