26

I am trying to make this VideoView to appear in full screen mode :

public class ViewVideo extends Activity {
  private String filename;
  private static final int INSERT_ID = Menu.FIRST;

  @Override
  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.gc();
        Intent i = getIntent();
        Bundle extras = i.getExtras();
        filename = extras.getString("videofilename");
        VideoView vv = new VideoView(getApplicationContext());
        setContentView(vv);
        vv.setVideoPath(filename);
        vv.setMediaController(new MediaController(this));
        vv.requestFocus();
        vv.start();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      super.onCreateOptionsMenu(menu);
      menu.add(0, INSERT_ID, 0,"FullScreen");

      return true;
  }

  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
      switch(item.getItemId()) {
      case INSERT_ID:
          createNote();
      }
      return true;
  }

  private void createNote() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                             WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  }
}

The video is playing from sdcard. Only thing is when I click on the full-screen menu button, the application "stops unexpectedly".

Please help me out, how to get the video to run in full screen? Thanks in advance.

0

6 Answers 6

40

No need of code to play video in full screen mode

Apply the following layout format over the xml containing the videoview it will for sure will play the video in full screen mode. as it is running mine :) Hope it helps

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent" >
   <VideoView android:id="@+id/myvideoview"
             android:layout_width="fill_parent"
             android:layout_alignParentRight="true"
             android:layout_alignParentLeft="true"
             android:layout_alignParentTop="true"
             android:layout_alignParentBottom="true"
             android:layout_height="fill_parent">
    </VideoView>
 </RelativeLayout>
Sign up to request clarification or add additional context in comments.

3 Comments

for performing same thing the above layout can be applied using a code when full screen mode button is to be pressed . it worked great for me.
this would just fill the available width and height of the application window. you still end up with your applications titlebar and the system icons (date/time battery status etc) at the top. The unspoken assumption here is that he wants the video to fill the entire screen.
Hi javanator i am facing the same problem while playing the video in videoview and run it in tablet. i have used your solution but it still having the center alligned video in tablet and 2 black lines in both left and right side. What to do. here is my question in so. stackoverflow.com/questions/14708457/…
36

when you click an menu item. you have to start a New Activity. for that Activity you have to set the theme attribute in the Manifest. set this value that is

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

thats it.

Comments

7

Perhaps it's because you have to add following code:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
    WindowManager.LayoutParams.FLAG_FULLSCREEN,  
     WindowManager.LayoutParams.FLAG_FULLSCREEN);

before setContentView(your_content_view) to get rid of app title bar. I know its a very late reply but somebody might find it useful.

2 Comments

its not perhaps, it is for sure..:)
2017 and still useful, never late :P
1

Due to my experienced, you can only use Relative-Layout View for you video to be stretch on portrait and landscape. Linear-layout view can only stretch video on Landscape, you can try the two view without writing any code and prove my theory

Comments

0

Okey, Let's try like this, this was suitable for my full screen.

    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"

Comments

0

Portrait layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@android:color/black">
    <VideoView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />
</FrameLayout>

Landscape layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black">
    <VideoView
        android:id="@+id/video_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"/>
</FrameLayout>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.