开发者

Android-Video View in Fullscreen

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.


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>


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.


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.


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


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

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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜