【问题标题】:how to display popup frame to play video on webview android如何显示弹出框以在 webview android 上播放视频
【发布时间】:2013-02-24 23:12:49
【问题描述】:

当用户单击我的网络视图上的视频链接时,我想显示弹出框,而不是弹出框应该显示并进入该帧布局视频表面,从 sd 卡播放我的视频,视频完成后,帧布局自动关闭,网络-view 再次显示。 我在 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>

【问题讨论】:

    标签: android android-layout android-webview


    【解决方案1】:

    为此尝试自定义对话框

        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
        {  } }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      相关资源
      最近更新 更多