Android 媒体播放器问题

发布于 2024-12-16 21:05:54 字数 1574 浏览 2 评论 0原文

我通过拉起媒体播放器获得了一个可以在 WebView 中播放的 HTML-5 视频,但是,它的显示方式如下图所示。有人知道我如何扩展它以使其全屏显示吗?或者,居中?

下面的代码创建 WebView,然后创建 WebChromeClient 来播放其中的 HTML-5 视频。

   myWebView.setWebChromeClient(new WebChromeClient() {  

                public void onShowCustomView(View view, CustomViewCallback callback) {  
                        super.onShowCustomView(view, callback);  
          if (view instanceof FrameLayout){  
              FrameLayout frame = (FrameLayout) view;  
              if (frame.getFocusedChild() instanceof VideoView){  
                  VideoView video = (VideoView) frame.getFocusedChild();  
                  frame.removeView(video);
                  setContentView(video);  
                  video.setOnCompletionListener(new OnCompletionListener() {  

                     @Override  
                     public void onCompletion(MediaPlayer mp) {  
                         mp.stop();  
                         setContentView(R.layout.mnwv_main);  
                     }  
                 });  
                  video.setOnErrorListener(new OnErrorListener() {  

                     @Override  
                     public boolean onError(MediaPlayer mp, int what, int extra) {  
                         return false;  
                     }  
                 });  
                  video.start();  
              }  
          }  
      }  
      }); // new WebChromeClient() ends...        

    myWebView.loadUrl("http://www.meanwhileinwv.com");

}

I have gotten an HTML-5 video to play in WebView by pulling up the Media Player, BUT, it is being displayed as it is in the image below. Anyone know how I could expand this to make it full screen?? Or, center it?

Below is the code that creates the WebView and then creates the WebChromeClient to play the HTML-5 Video within.

   myWebView.setWebChromeClient(new WebChromeClient() {  

                public void onShowCustomView(View view, CustomViewCallback callback) {  
                        super.onShowCustomView(view, callback);  
          if (view instanceof FrameLayout){  
              FrameLayout frame = (FrameLayout) view;  
              if (frame.getFocusedChild() instanceof VideoView){  
                  VideoView video = (VideoView) frame.getFocusedChild();  
                  frame.removeView(video);
                  setContentView(video);  
                  video.setOnCompletionListener(new OnCompletionListener() {  

                     @Override  
                     public void onCompletion(MediaPlayer mp) {  
                         mp.stop();  
                         setContentView(R.layout.mnwv_main);  
                     }  
                 });  
                  video.setOnErrorListener(new OnErrorListener() {  

                     @Override  
                     public boolean onError(MediaPlayer mp, int what, int extra) {  
                         return false;  
                     }  
                 });  
                  video.start();  
              }  
          }  
      }  
      }); // new WebChromeClient() ends...        

    myWebView.loadUrl("http://www.meanwhileinwv.com");

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2024-12-23 21:05:54

有人知道我如何扩展它以使其全屏显示吗?

逆时针旋转手机 90 度(如果您有相对较新的设备,也可以顺时针旋转)。这将使视频播放得更大,但它很可能无法全屏显示,因为视频的宽高比可能与您的设备的宽高比不匹配。

或者,居中?

请参阅:

将视频放置在 VideoView 内

Anyone know how I could expand this to make it full screen?

Turn your phone 90 degrees counter-clockwise (or possibly also clockwise, if you have a relatively new device). That will get the video playing larger, though it cannot be full screen in all likelihood, as the video's aspect ratio probably does not match that of your device.

Or, center it?

See:

Position Video Inside a VideoView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文