简体   繁体   English

Android全屏视频观看

[英]Android-Video View in Fullscreen

I am trying to make this VideoView to appear in full screen mode : 我想让这个VideoView以全屏模式显示:

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. 该视频正在播放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. 在包含videoview的xml上应用以下布局格式,它肯定会以全屏模式播放视频。 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. 对于该Activity,您必须在Manifest中设置theme属性。 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. setContentView(your_content_view)之前摆脱app标题栏。 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 线性布局视图只能在Landscape上拉伸视频,您可以尝试两个视图而无需编写任何代码并证明我的理论

哦,让我们试试这个,这适合我的全屏。

    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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM