2

我想在用户单击我的 web 视图上的视频链接时显示弹出框,而不是弹出框应该显示并进入该帧布局视频表面播放我的视频从 sd 卡和视频完成后帧布局自动关闭并且 web 视图是再次显示。我在 google 和 stackoverflow 上搜索有一些帮助,但我不了解编写代码的技术。我的脑海中有一个困惑,我如何显示弹出框架布局以及如何显示 webview。

目前我正在检查扩展,如果我发现视频扩展比我触发媒体播放器意图。但我不希望那样。我希望它应该在我的网络视图中播放,但在弹出式视频表面中。

这是我的代码,我的布局文件只包含 webview 没有其他内容,我正在从我的资产文件夹加载 html,我正在从 sd 卡播放视频..

任何帮助表示赞赏

    setContentView(R.layout.activity_main);        
    WebView webView = (WebView) findViewById(R.id.webview);
    String html = "<embed src=\"file:///android_asset/" + "test.html" + " \"play=\"true\" loop=\"true\" width=\"100%\" height=\"100%\"> <embed>";
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    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(".m4v")) {
                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);
            }
        }
    });}
    }

这是HTML文件

<html lang="en">
<head>
<meta charset=utf-8>
<title>Sample HTML5 Structure</title> 
<SCRIPT LANGUAGE="JavaScript">
function playvideo(url){
window.location=url;
 }
 </SCRIPT>
</head>
 <body>
<video src="file:///sdcard/kummar.m4v" width="300"      onclick="playvideo('file:///sdcard/ku<p>testing of video element.</p>
  </video>
  </body>
  </html>
4

1 回答 1

0

为此尝试自定义对话框

    Dialog mVideoDialog ;
VideoView mVideoFullScreen;
 MediaController controller;

在你的 increate 方法中添加这个

     mVideoDialog = new Dialog(this);
    mVideoDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mVideoDialog.setContentView(R.layout.dialog);
    mVideoDialog.setOnKeyListener(this);
    mVideoFullScreen = (VideoView) mVideoDialog.findViewById(R.id.videoview1);
    controller = new MediaController(this);
    HelloWebViewClient webViewClient = new HelloWebViewClient();
    webView.setWebViewClient(webViewClient);
     }

 private class HelloWebViewClient extends WebViewClient
{ 
 @Override public boolean shouldOverrideUrlLoading(WebView view, String url)
 {

     if (url.contentEquals("file:///android_asset/01")) {
         showVideo(01); //check user click url from webview and pass int
     }
     else if (url.contentEquals("file:///android_asset/02"))
     {
        showVideo(02);//pass int to determine which video to play
     }
     else
     {
     System.out.println("DDD URL: "+url.toString()); view.loadUrl(url);  
     }
     return true;       
     }

这是 showVideo 方法

public void showVideo(int i) {
    // TODO Auto-generated method stub
    if(i==01)
    {
     mVideoDialog.show();
     mVideoFullScreen.setVideoPath("file:///sdcard/video file name.m4v");
     controller.setMediaPlayer(mVideoFullScreen);
     mVideoFullScreen.setMediaController(controller);
     mVideoFullScreen.requestFocus();
     mVideoFullScreen.start();
    }else
    {  } }
于 2013-02-25T12:43:50.247 回答