在横屏模式下视频无法全屏显示

3
我正在使用一个用XML设计的视频视图。在竖屏模式下,该视频是全屏的,但当它转到横屏模式时,它会左对齐,宽度和高度都被包裹起来,而不是全屏显示。
我参考了以下链接,但仍然没有解决方法: 全屏VideoView未居中 Android-Video View全屏 有人知道答案吗?
更新:这里是我的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();
}

}


1
@AndroSelva,你能看到我的XML吗? - tejas
只是确认一下,视频视图在播放视频时不适合还是它在图形布局中本身就不适合,也就是说,在你设计时就不适合? - Andro Selva
玩的时候不适合。当我用图形布局查看时,可以看到它被填充了。 - tejas
能否给我视频的链接?我可以试一下吗? - Andro Selva
尝试使用这个解决方案,希望对你有用。 - Chirag Shah
显示剩余3条评论
1个回答

33

你确定它没有填满屏幕吗?对我来说很好用。这是XML文件:

main.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();
}

竖屏截图

enter image description here

横屏截图

enter image description here


哦,这对你起作用了,是的,我150%确定它之前没有起作用。等一下,我试试这个。 - tejas
你的代码能够运作,但是你能否控制这些功能呢?我指的是播放/暂停、快进/快退按钮。我无法得到这些按钮,当我旋转屏幕时,它又从头开始串流。 - tejas
你好,我遇到了一个有些奇怪的问题。我创建了一个支持Surface View的简单媒体播放器,它可以在竖屏和横屏模式下正常工作。但是,在Galaxy和HTC 1设备上却无法正常运行...你有什么想法或建议吗? - CoDe
@AndroSelva 谢谢,这个答案对我有用,但是如果多个视频有多个分辨率怎么办?您目前的解决方案会拉伸一些视频。 - Arun Badole
@tejas 你有解决办法吗?我也遇到了同样的问题,它会从头开始重新流媒体。 - Erum
显示剩余7条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接