视频不在webview的同一页面上播放?

时间:2011-12-15 09:21:37

标签: android

我有一个要求,我必须在webview中播放HTML5视频。我使用意图输出,但它将页面转移到播放器。我的要求是在同一页面播放视频。根据我的信息Android浏览器的视频编解码器从Android 2.3开始,但它不适合我。谁能帮助我? 这是我的代码:

    WebView webView = (WebView) findViewById(R.id.webview);
    String html = "<embed src=\"file:///android_asset/" + "Sample.html" + "              \"play=\"true\" loop=\"true\" width=\"100%\" height=\"100%\"> <embed>";
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setPluginsEnabled(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);
    WebViewClient webViewClient = new WebViewClient();
    webView.setWebViewClient(webViewClient);
    webView.setWebViewClient(new WebViewClient(){

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
        }

        @Override
        public void onLoadResource(WebView view, String url) {
                if (url.endsWith(".mp4")) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri
                        .parse(url));
                intent.setDataAndType(Uri.parse(url), "video/*");
                view.getContext().startActivity(intent);

            }
            else
            {
                super.onLoadResource(view, url);
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.endsWith(".mp4")) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri
                        .parse(url));
                intent.setDataAndType(Uri.parse(url), "video/*");
                view.getContext().startActivity(intent);
                return true;
            }
            else
            {
                return super.shouldOverrideUrlLoading(view, url);
            }
        }
    });
}

}

0 个答案:

没有答案