在android中使用html5在webview中播放mp4视频

Shu*_*ham 12 video html5 android-webview

我正在尝试在Android中使用HTML5webView中播放mp4视频,但遗憾的是它无法正常工作,所以任何人都可以帮助我,我该怎么做?

这是我的代码 HTML文件,名称为new2.html

<video width="365" height="200" src="/sdcard/Download/video.mp4" controls autobuffer></video>


<!--<!DOCTYPE html>
<html>
<body>

<video width="320" height="240" controls autoplay>
  <source src="/sdcard/Download/video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

</body>
</html>-->
Run Code Online (Sandbox Code Playgroud)

Java文件是:

public class WebActivity extends Activity {
     WebView wv;  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
         setContentView(R.layout.web_activity);  

         wv = (WebView) findViewById(R.id.webview);  
         wv.loadUrl("file:///android_asset/new2.html");
         wv.getSettings().setAllowFileAccess(true);
         wv.getSettings().setJavaScriptEnabled(true);
         wv.getSettings().setPluginsEnabled(true);
        // webview.loadUrl("file:///android_asset/new.html");
    }

}
Run Code Online (Sandbox Code Playgroud)

XML文件是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <WebView
        android:id="@+id/webview" 
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Fou*_*_lo 1

您需要通过本地主机(file://localhost/)调用您的文件,否则您的手机将无法识别出您正在请求权限。通过使用没有本地主机的浏览器,您将关闭卫星,并且无法在重新租用时恢复。

您正在获取要显示的控件,因为它们来自公共 html 文件夹,但您的源(视频)却不是。