Android的VideoView不打纵向 [英] Android VideoView not playing Portrait Orientation

查看:174
本文介绍了Android的VideoView不打纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总平台:
使用Android SDK 16在Eclipse开发。

THE PLATFORM: Developing in Eclipse using Android SDK 16.

问题:
我有一个是为了填补在480×800(纵向),整个屏幕上VideoView元素,它起着罚款,但不会定位为纵向。它坚持在横向模式和纵横比歪斜,以适应这种方式。

THE PROBLEM: I have a VideoView element that is supposed to fill the entire screen in 480x800 (PORTRAIT ORIENTATION) and it plays fine, but will not orient to portrait. It sticks in landscape mode and the aspect ratio is skewed to fit that way.

我曾尝试:


  • 采用了android:screenOrientation =清单中
  • 画像
  • 采用了android:方向与容器=垂直和VideoView本身

  • 使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);之前,我打电话的setContentView

  • 试图设置布局宽度和高度,而不是480dpx800dp FIL​​L_PARENT的

  • 试图将VideoView宽度和高度设置为480像素点¯x800DP,而不是FILL_PARENT

  • 关闭自动旋转显示

的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="480dp"
    android:layout_height="800dp"
    android:background="#000000" 
    android:orientation="vertical" > 

    <VideoView
        android:id="@+id/opening_video"
        android:layout_width="480dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentBottom="true" 
        android:layout_height="800dp"
        android:orientation="vertical" /> 

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/transparent_button"
        android:contentDescription="@string/back_button_desc"
        android:background="@android:color/transparent" />

</RelativeLayout>

总code:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_start_screen);

        VideoView videoView = (VideoView) findViewById(R.id.opening_video);  

        Uri pathToVideo = Uri.parse("android.resource://com.example.consumerengage/" + R.raw.opening_tablet);  
        videoView.setVideoURI(pathToVideo);  
        videoView.setOnPreparedListener(new OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });        

        videoView.requestFocus();  
        videoView.start(); 

       // boolean isPlaying = videoView.isPlaying() ; 

       // videoView.stopPlayback();  
       // videoView.clearFocus(); 

       addListenerOnButton();

    }

问题:
什么我已经尝试是成功的。我怎样才能让我的480x800的视频,纵向玩?

THE QUESTION: Nothing I have attempted has been successful. How can I get my 480x800 video to play in portrait orientation?

推荐答案

下面是我落得这样做:

问题是操作系统版本。如果是ICS(4.0)以上,它会播放视频在其一侧,所以在检测到14或更大android.os.Build.VERSION.SDK_INT,我加载是建立在其一侧的视频,这样它播放正确的做法。

The issue was the OS version. If it was ICS (4.0) and above, it would play the video on its side, so upon detecting android.os.Build.VERSION.SDK_INT of 14 or greater, I load the video that is built on its side so it plays the right way.

这是一个很无聊的解决办法,而且我从来没有真正得到了回答我的问题。视频不应该发挥这样的。

This is a very silly workaround, and I never really got the answer to my question. The video should not play like that.

这篇关于Android的VideoView不打纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆