Android VideoView不播放纵向视图
平台: 使用Android SDK 16在Eclipse中开发 问题: 我有一个VideoView元素,它应该以480x800(纵向方向)填充整个屏幕,它播放效果很好,但不会面向纵向。它坚持在横向模式,纵横比是倾斜的,以适应这种方式 我的尝试:Android VideoView不播放纵向视图,android,orientation,android-videoview,portrait,Android,Orientation,Android Videoview,Portrait,平台: 使用Android SDK 16在Eclipse中开发 问题: 我有一个VideoView元素,它应该以480x800(纵向方向)填充整个屏幕,它播放效果很好,但不会面向纵向。它坚持在横向模式,纵横比是倾斜的,以适应这种方式 我的尝试: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?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();
}
- 在清单中使用android:screenOrientation=“纵向”
- 在容器中使用android:orientation=“vertical”和视频视图本身
- 使用setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u Grait);就在我调用setContentView之前
- 正在尝试将布局宽度和高度设置为480dpx800dp,而不是填充
- 尝试将VideoView宽度和高度设置为480px x 800dp,而不是填充
- 关闭自动旋转显示器
<?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视频以纵向播放 试试这个:
<?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>
希望这有帮助。也要检查您的清单文件。您确定您的视频是480x800而不是800x480吗?800x480是一种标准分辨率,如果用手机以纵向方式录制视频,输出仍将为800x480,要正常播放,视频应旋转90度。您所描述的是,如果您尝试在480x800视频视图中播放800x480视频,将会发生什么情况。如果是这种情况,您可以使用Windows Live Moviemaker或iMovie等视频编辑软件(如果您在Mac上)对其进行旋转。您使用的是
dp
,您应该使用px
:
以下是我最后做的事情: 问题是操作系统版本。如果是ICS(4.0)或更高版本,它会在其一侧播放视频,因此在检测到android.os.Build.VERSION.SDK_INT为14或更大时,我会加载在其一侧构建的视频,以便它以正确的方式播放
这是一个非常愚蠢的解决办法,我从来没有真正得到我的问题的答案。视频不应该这样播放。将“我的XML”更改为上述设置后,视频仍然水平播放,而不是垂直播放。@RickS您犯的错误是为布局和视频视图定义了固定的高度和宽度。只需使用默认匹配父项,并在清单文件的活动中写入android:screenOrientation=“纵向”。从Manifeat文件中的活动中删除android:screenOrientation我们实际上使用专业编辑软件Final cut Pro以几种不同的分辨率、编解码器和方向剪切视频。奇怪的是,它在一款平板电脑上播放得很好,但在另一款平板电脑上却很奇怪。coby kyros 7036(ICS)播放视频的方式错误,而coby kyros 7022(姜饼)播放的方式正确。