3

I am working on one custom video player in android. I am using VideoView for playing video. Initially my VideoView will be of some size (lets say size = (width , height) = (400, 300)). One of the control button of my custom video view is "Expand/Collapse". After clicking on "Expand/Collapse" button, I want to set VideoView size to fullscreen(means device's full screen size) if current VideoView size is of Inline and vice versa(from full screen to Inline also).

Do anybody know the proper way to do the above task?

M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
macpandit
  • 835
  • 1
  • 7
  • 11

1 Answers1

10

First of all, you got guts to ask a Android question and have a iOS logo ;) (kidding)

But, I think you can use this:

    DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
    android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
    params.width =  metrics.widthPixels;
    params.height = metrics.heightPixels;
    params.leftMargin = 0;
    videoView.setLayoutParams(params);

and to set it back:

    DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
    android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
    params.width =  (int) (400*metrics.density);
    params.height = (int) (300*metrics.density);
    params.leftMargin = 30;
    videoView.setLayoutParams(params);

I assume that you know how to make a OnClickListener.

I got the information here: VideoView Full screen in android application

Edit1
I can think of 2 things quickly.
1. Add this: getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
2. or try this:

YourButton.setVisibility(View.GONE);

or

YourButton.setVisibility(View.INVISIBLE);
Community
  • 1
  • 1
Bigflow
  • 3,616
  • 5
  • 29
  • 52
  • I went through this answer, but here the problem is if my layout is having any single extra control like button or textview with VideoView, then VideoView is not taking full screen of the device. Its keeping the space for those controls and showing VideoView in remaining portion of the screen. But I need to show the video in fullscreen irrespective of extra controls. (If there is a textview with VideoView in linear layout, then while clicking on fullscreen button, VideoView should take the full screen control and should hide textview) – macpandit Jan 16 '13 at 09:46
  • yeah Bigflow :) basically I'm iOS apps developer but nowadays exploring android sdk. I hope u got my exact issue from above comment. Any kind of help on this issue is highly appreciable :) – macpandit Jan 16 '13 at 09:58
  • 1
    @macpandit Made an Edit. Hope this works. To be honest, never used VideoView yet :). But trying to help. – Bigflow Jan 16 '13 at 10:00
  • It works like a charm in my sample app. Actually hiding button control works.. Thank you so much for this highly appreciable help :) – macpandit Jan 16 '13 at 11:02
  • @Bigflow i followed your code but the issue is ... i have videoview and somemore views on top of videoview and similarly viewpager below videoview layout .... not i hide viewpager in landcape and set videoview to full parent but still my layout that contains seekbar is present on top of videoview but not in parent bottom of videoview while in portrait its working fine – Erum Sep 18 '15 at 09:01