简体   繁体   English

Android VideoView无法播放纵向方向

[英]Android VideoView not playing Portrait Orientation

THE PLATFORM: Developing in Eclipse using Android SDK 16. 平台:使用Android SDK 16在Eclipse中开发。

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. 问题:我有一个VideoView元素应该以480x800(PORTRAIT ORIENTATION)填满整个屏幕,它可以很好地播放,但不会定向到肖像。 It sticks in landscape mode and the aspect ratio is skewed to fit that way. 它坚持横向模式,纵横比倾斜以适应这种方式。

WHAT I HAVE ATTEMPTED: 我曾经尝试过什么:

  • using android:screenOrientation="portrait" in manifest 在清单中使用android:screenOrientation =“portrait”
  • using android:orientation="vertical" in the container and the VideoView itself 在容器和VideoView本身使用android:orientation =“vertical”
  • using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); right before I call setContentView 就在我调用setContentView之前
  • trying to set the layout width and height to 480dpx800dp instead of fill_parent 尝试将布局宽度和高度设置为480dpx800dp而不是fill_parent
  • trying to set the VideoView width and height to 480px x 800dp instead of fill_parent 尝试将VideoView宽度和高度设置为480px x 800dp而不是fill_parent
  • switching off the auto rotate display 关闭自动旋转显示

THE XML: 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>

THE 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();

    }

THE QUESTION: Nothing I have attempted has been successful. 问题:我没有尝试过任何成功的事情。 How can I get my 480x800 video to play in portrait orientation? 如何让我的480x800视频以纵向方式播放?

Are you certain your video is is 480x800 and not 800x480? 你确定你的视频是480x800而不是800x480吗? 800x480 is a standard resolution, if you record a video in portrait with a phone the output will still be 800x480 and to have normal playback the video should be turned 90 degrees. 800x480是标准分辨率,如果您使用手机以纵向录制视频,则输出仍为800x480,要正常播放,视频应旋转90度。 What you are describing is what would happen if you try to play a 800x480 video in a 480x800 videoView. 您所描述的是如果您尝试在480x800 videoView中播放800x480视频会发生什么。 If this is the case you could rotate it with video editing software like Windows Live Moviemaker or iMovie if you are on Mac. 如果是这种情况,您可以使用视频编辑软件(如Windows Live Moviemaker或iMovie)旋转它(如果您使用的是Mac)。

You are using dp where you should be using px : 您正在使用dp ,您应该使用px

<VideoView
    android:id="@+id/opening_video"
    android:layout_width="480px"
    android:layout_alignParentRight="true"
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_height="800px"
    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" />

Or, alternatively (and better) - just use match_parent (or fill_parent ): 或者,或者(更好) - 只需使用match_parent (或fill_parent ):

<VideoView
    android:id="@+id/opening_video"
    android:layout_width="match_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_height="match_parent"
    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" />

Try this: 尝试这个:

<?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="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"> 

    <VideoView
        android:id="@+id/opening_video"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" /> 

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

Hope this helps. 希望这可以帮助。 And also check your manifest file too. 并检查您的清单文件。

Here's what I ended up doing: 这是我最终做的事情:

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. 如果它是ICS(4.0)及以上,它会播放视频,所以一旦检测到14或更高的android.os.Build.VERSION.SDK_INT,我加载其侧面构建的视频,以便它播放正确的路。

This is a very silly workaround, and I never really got the answer to my question. 这是一个非常愚蠢的解决方法,我从来没有真正得到我的问题的答案。 The video should not play like that. 视频不应该那样播放。

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

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