how to play video in android webview?

∥☆過路亽.° 提交于 2020-01-03 03:01:27

问题


I want to put a web into webview.These is a video in the web.The video's format is wmv.I put the web in the android project "assets" file.Now I can scan the web,but the video can't play.This is the code on below.Who can help me?Thanks.

public class WebViewActivity extends Activity {
    private WebView webview;
    private WebSettings webSettings;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webview = (WebView) findViewById(R.id.webView);
        webSettings = webview.getSettings();

        webSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
        webSettings.setBuiltInZoomControls(true);

        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setPluginState(PluginState.ON);
        webview.getSettings().setPluginsEnabled(true);
        webview.loadUrl("file:///android_asset/demo/html/demo.html");
        webview.setWebViewClient(new MyWebClient());

    }

    private class MyWebClient extends WebViewClient {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

    }

}

回答1:


WMV is a proprietary Microsoft video format. Chances are Android doesn't have a codec for it. You should convert it to something standard e.g H264.

Unfortunately video encoding is a minefield of proprietary tech. There are a few open source converters available. FFMPEG is probably the most extensive. There's a handy GUI for this called WinFF (if you're using windows).

You can test your HTML file by putting it and your video onto the SDcard and see if it works in it's simplest form. Try with different video formats as a sanity check.




回答2:


WMV isn't widely supported on Android devices, but there are various tools to convert format.

https://gist.github.com/3718414 is a sample showing an Android webview and HTML5 player that works with the video codecs that Android supports (.mp4 is best for progressive video as it has by far the widest support)



来源:https://stackoverflow.com/questions/8177206/how-to-play-video-in-android-webview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!