繁体   English   中英

Android VideoView无法播放纵向方向

[英]Android VideoView not playing Portrait Orientation

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

问题:我有一个VideoView元素应该以480x800(PORTRAIT ORIENTATION)填满整个屏幕,它可以很好地播放,但不会定向到肖像。 它坚持横向模式,纵横比倾斜以适应这种方式。

我曾经尝试过什么:

  • 在清单中使用android:screenOrientation =“portrait”
  • 在容器和VideoView本身使用android:orientation =“vertical”
  • 使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 就在我调用setContentView之前
  • 尝试将布局宽度和高度设置为480dpx800dp而不是fill_parent
  • 尝试将VideoView宽度和高度设置为480px x 800dp而不是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>

编码:

@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视频以纵向方式播放?

你确定你的视频是480x800而不是800x480吗? 800x480是标准分辨率,如果您使用手机以纵向录制视频,则输出仍为800x480,要正常播放,视频应旋转90度。 您所描述的是如果您尝试在480x800 videoView中播放800x480视频会发生什么。 如果是这种情况,您可以使用视频编辑软件(如Windows Live Moviemaker或iMovie)旋转它(如果您使用的是Mac)。

您正在使用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" />

或者,或者(更好) - 只需使用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" />

尝试这个:

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

希望这可以帮助。 并检查您的清单文件。

这是我最终做的事情:

问题是操作系统版本。 如果它是ICS(4.0)及以上,它会播放视频,所以一旦检测到14或更高的android.os.Build.VERSION.SDK_INT,我加载其侧面构建的视频,以便它播放正确的路。

这是一个非常愚蠢的解决方法,我从来没有真正得到我的问题的答案。 视频不应该那样播放。

暂无
暂无

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

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