【问题标题】:Video view is not full screen in landscape mode横向模式下视频视图不是全屏
【发布时间】:2012-06-14 05:35:56
【问题描述】:

我正在使用用 xml 设计的视频视图。此视频在纵向模式下是全屏的,但当它变成横向模式时,它是左对齐的,并且宽度和高度都被换行而不是全屏。

我参考了这些,但仍然没有解决方案。

Fullscreen VideoView isn't Centered

Android-Video View in Fullscreen

有人知道答案吗?

更新:这是我的 xml

<?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/youtubewebView"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true" android:layout_gravity="fill" />

</RelativeLayout>

更新 2:

public class VideoStreamingActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final VideoView videoView = (VideoView)findViewById(R.id.your_video_view);
    String videoUrl = "http://www.pocketjourney.com/downloads/pj/video/famous.3gp";
    try {
    Uri uri = Uri.parse(videoUrl);
    videoView.setVideoURI(uri);
    videoView.setMediaController(new MediaController(this));
    videoView.requestFocus();
    //videoView.start();
    videoView.setOnErrorListener(new OnErrorListener() {

        @Override
        public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
            Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
            return true;
        }
    });

    }catch (Exception e) {
        e.printStackTrace();
    }

    videoView.setOnPreparedListener(new OnPreparedListener() {

        public void onPrepared(MediaPlayer mp) {
            videoView.start();
        }
    });

}

@Override
protected void onPause() {
    Toast.makeText(getApplicationContext(), "pause", Toast.LENGTH_SHORT).show();
    super.onPause();
}

@Override
protected void onRestart() {
    Toast.makeText(getApplicationContext(), "restart", Toast.LENGTH_SHORT).show();
    super.onRestart();
}

@Override
protected void onResume() {
    Toast.makeText(getApplicationContext(), "resume", Toast.LENGTH_SHORT).show();
    super.onResume();
}

}

【问题讨论】:

  • @AndroSelva,你能看到我的 xml 吗?
  • 你测试它时只设置了高度和宽度来填充父级吗?
  • 不,我尝试了所有方法。我的意思是匹配父属性,甚至是硬编码的高度和宽度。然后它被包裹起来了。
  • 只是为了确认一下,视频视图是不是在播放视频时不适合,或者它只是不适合图形布局本身,也就是说,当你设计它时?
  • 播放时不合适。当我查看图形布局时,我可以看到它已填充

标签: android xml landscape


【解决方案1】:

您确定它没有填满屏幕吗?这对我来说可以。这是xml文件,

ma​​in.xml

<?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"
    android:orientation="vertical" >

    <VideoView android:id="@+id/video"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
       android:layout_alignParentRight="true"
       android:layout_alignParentBottom="true"
       android:layout_alignParentTop="true"
        />
</RelativeLayout>

onCreate()

VideoView video=null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    video=(VideoView)findViewById(R.id.video);
    video.setVideoURI(Uri.parse("http://www.pocketjourney.com/downloads/pj/video/famous.3gp"));
    video.start();
}

纵向模式的屏幕截图

横向模式的屏幕截图

【讨论】:

  • 哦,这对你有用,是的,我 150% 确定它不起作用。等等我试试这个
  • 还是一样,在竖屏模式下最初会全屏。当我做风景时,它会丢失它并与左侧对齐。现在,当我将其转回纵向时,即使纵向也不是全屏高度
  • 而我的oncreate是这样的,videoView.setVideoURI(uri); videoView.setMediaController(new MediaController(this)); videoView.requestFocus(); videoView.start();
  • 您的代码在某种程度上可以正常工作,但您可以在那里获得控件吗?我指的是播放/暂停和 FF/Rw 按钮。我没有得到,当我旋转屏幕时,它再次从第一个开始流式传输
  • 你必须使用 MediaController。默认情况下,它就像屏幕底部的弹出窗口一样,并与 VideoView 重叠。所以应该没有问题。要连续播放视频,您必须覆盖 onResume() 和 onPause()。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-21
  • 2013-06-24
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
相关资源
最近更新 更多