0

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");

}
comead
  • 577
  • 2
  • 13
  • 29

1 Answers1

0

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

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • No, I cant just turn it 90 degrees. The activity is set to portrait. I just want to force it into landscape when a video starts. the video isnt playing in a video view... the question says that i got an HTML-5 video to run in a WebView, so that doesn't help at all. – comead Nov 19 '11 at 23:34
  • @comead: "I just want to force it into landscape when a video starts" -- then don't set the activity to portrait. Either set it to landscape, or leave it alone and allow the user to actually decide how they would like to use their device, or don't display the video in the `WebView` and write a separate landscape activity for displaying the video. – CommonsWare Nov 19 '11 at 23:39
  • how would you go about changing what I have to using a new activity that uses a VideoView? Ive never used VideoView. And, I have to leave it set to portrait for that activity because before you get to the video, that cant be in landscape. – comead Nov 19 '11 at 23:45
  • @comead: "how would you go about changing what I have to using a new activity that uses a VideoView?" -- I don't know what you have. I assume you have a link that leads to a page that is displaying the video. Teach your `WebViewClient` via `shouldOverrideUrlLoading()` to route control to some activity that plays videos. It doesn't even have to be your player -- most likely, the device has one built in, so an `ACTION_VIEW` `Intent` with an appropriate URL and MIME type should suffice. – CommonsWare Nov 19 '11 at 23:47
  • @comead: "And, I have to leave it set to portrait for that activity because before you get to the video, that cant be in landscape." -- sure it can. The only thing that can be said about portrait is that it is narrower than landscape. Are you saying that you can't write an app that will work on a tablet? Or a 720p phone like the HTC Rezound or Galaxy Nexus? After all, their portrait width (720-800px) is as wide as or wider than many devices' landscape width. – CommonsWare Nov 19 '11 at 23:51
  • Sorry, I thought I had posted the code. I edited the question to include the code. I dont know where to go to do what you are saying. So should I just drop the WebChromeClient? – comead Nov 19 '11 at 23:52
  • @comead: Well, to get your centering, you would follow the instructions in the link I gave you, setting the size and layout gravity of the `VideoView` you pasted above that you claimed didn't exist ("the video isnt [sic] plaing in a video view"). In terms of having it be landscape, combine the "detect a link click" logic from https://github.com/commonsguy/cw-android/tree/master/WebKit/Browser3 and the "play a video" logic from https://github.com/commonsguy/cw-advandroid/tree/master/Media/Video. The latter uses a local MP4 file; you'd use a URL to your video. – CommonsWare Nov 20 '11 at 00:02
  • the VideoView is never mentioned in any XML so, I couldnt do that centering is there another way? – comead Nov 20 '11 at 00:16
  • any time i try to add it in, the screen is black. – comead Nov 20 '11 at 00:18
  • @comead: You can set the size and layout gravity of your `VideoView` in your Java code. For example: http://stackoverflow.com/questions/4301565/setting-textviews-attributes-programmatically – CommonsWare Nov 20 '11 at 00:27
  • @comead: Sorry, but you are now beyond my ability and willingness to assist further. – CommonsWare Nov 20 '11 at 00:41
  • well can you explain what you mentioned earlier? Teaching your WebViewClient via shouldOverRideUrlLoading to route control to some activity that plays videos? You said it but never expounded upon it – comead Nov 20 '11 at 00:43