首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安卓VideoView不玩面向肖像的游戏

安卓VideoView不玩面向肖像的游戏
EN

Stack Overflow用户
提问于 2012-10-28 21:53:59
回答 4查看 7.5K关注 0票数 13

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

问题:我有一个VideoView元素,它应该在480x800 (纵向方向)中填充整个屏幕,它播放得很好,但不会指向肖像。它附着在景观模式和纵横比倾斜,以适应这种方式。

我所尝试的:

  • 在舱单中使用android:screenOrientation=“肖像”
  • 在容器和android:orientation=本身中使用VideoView“垂直”
  • 在调用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);之前使用setContentView
  • 尝试将布局宽度和高度设置为480 dpx800dp,而不是fill_parent。
  • 尝试将VideoView宽度和高度设置为480 pxx800dp,而不是fill_parent
  • 关闭自动旋转显示

THE XML:

代码语言:javascript
运行
AI代码解释
复制
<?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>

代码:

代码语言:javascript
运行
AI代码解释
复制
@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视频在肖像方向播放?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-08-08 13:09:46

以下是我最后所做的:

问题是操作系统版本。如果它是ICS (4.0)或更高版本,它将在其一侧播放视频,因此当检测到14或更高的android.os.Build.VERSION.SDK_INT时,我会加载构建在其一侧的视频,使其以正确的方式播放。

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

票数 0
EN

Stack Overflow用户

发布于 2013-02-19 06:45:34

你确定你的视频是480x800而不是800x480吗? 800x480是一个标准的分辨率,如果你用手机记录一个视频,它的输出仍然是800x480,要正常播放,视频应该转90度。您所描述的是,如果您试图在480x800 videoView中播放800x480视频,会发生什么情况。如果是这样的话,你可以使用视频编辑软件,比如或者iMovie来旋转它,如果你在Mac上的话。

票数 2
EN

Stack Overflow用户

发布于 2013-02-20 11:02:35

您使用的是dp,而您应该使用px

代码语言:javascript
运行
AI代码解释
复制
<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):

代码语言:javascript
运行
AI代码解释
复制
<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" />

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13116538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档