Android - 在 html 代码中播放 html5 <video>

标签 android html video webview

我知道有很多关于这个的旧讨论,但我正在为新设备开发。

我想使用 WebView 在视频标签中显示 html5 视频。我想将其用于 Android 设备 4.0+ 甚至 4.1+。

我不想大量更改 WebView 代码。是否可以在不在顶部打开一些新 View 的情况下在 WebView 中显示电影?因为大多数答案都打开了新 View 来播放视频?我需要尽可能少的代码更正的简单解决方案。

欢迎提供任何代码或教程。

已更新

list :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.videoexample"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:hardwareAccelerated="true"
    >


    <activity
        android:name="com.example.videoexample.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

主文件:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebSettings;

public class MainActivity extends Activity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        webView = (WebView) findViewById(R.id.webView1);

        webView.setWebChromeClient(new WebChromeClient());
        webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
        webView.getSettings().setJavaScriptEnabled(true);

        // load the customURL with the URL of the page you want to display
        String pageURL = "http://www.vongola-restavracija-izola.si/powzyLibrary1/video.html";
        webView.loadUrl(pageURL);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

最佳答案

我开始工作 https://code.google.com/p/html5webview/

视频在那里工作。确保您的视频与安卓兼容

关于Android - 在 html 代码中播放 html5 <video>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21756378/

相关文章:

java - 如何在onBindViewHolder方法中管理字符串数组?

html - css标签栏高度问题

android - 在不扩展 Activity 的情况下将 Activity 添加到 Manifest

android - 如何像屏幕过滤器一样降低亮度

javascript - 替换 javascript 中的样式值

html - HTML5视频未在Chrome(ium)上显示包含非常大(本地)文件的图像

javascript - videojs 与 jquery 移动过渡

reactjs - 如何在react-native中实现透明背景的视频

android - 使用本地 list 的 repo 不起作用

javascript - 在用户输入时运行 javascript 函数