gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 12:43:39 26 4
gpt4 key购买 nike

我正在尝试在 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>-->

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");
}

}

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>

最佳答案

您需要通过本地主机调用您的文件 -- file://localhost/-- 否则您的手机将无法识别是您在请求权限。通过在没有 localhost 的情况下使用浏览器,您正在 ping 卫星并且无法在重新登录时恢复。

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

关于html - 在android中使用html5在webview中播放mp4视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16813448/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com