旋转回纵向时避免 Android VideoView 损坏 [英] Avoid Android VideoView corruption when rotating back to portrait

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

问题描述

我已经设法编写了一个能够从互联网查看 .3gp 文件的有限视频播放器.视频将以全屏居中显示,保持视频纵横比.此外,旋转不会中断视频,可以毫无问题地继续播放.

一切看起来都很好,但是...在我的 HTC Legend 上,当您旋转回纵向时,视频已损坏,并且不是全屏显示,而是以其原始像素大小显示.但再次旋转到风景作品并完美展示.任何想法为什么?不幸的是,我没有更多的硬件来测试这个,而且我已经没有任何想法可以测试了.

您可以从 .您添加了评论:

<块引用>

由于我们在我们想要处理我们自己的方向的 AndroidManifest.xml变化,我们调整屏幕大小以纵向或风景.

来自源代码 AndroidManifest.xml

android:configChanges="orientation|screenSize"

因此,如果您将此属性添加到清单中的活动元素,我会将其解释为活动将处理所有方向更改?不是你吗?

来自 Android 开发者

<块引用>

要声明您的活动处理配置更改,请编辑清单文件中的适当活动元素以包含android:configChanges 属性... 更多

所以你应该不需要:

@Overridepublic void onConfigurationChanged(Configuration newConfig) {super.onConfigurationChanged(newConfig);}

我创建了一个测试项目来检查是否是这种情况:

旋转视频流示例:https://github.com/TouchBoarder/RotatingVideoStream

我的结论:我不需要覆盖活动中的onConfigurationChanged"以在纵向和横向显示正确的视频,并且视频在旋转更改时继续播放.

随意改进和使用代码:)

I've managed to write a limited video player able to view a .3gp file from internet. The video will be shown centered full screen, maintaining the video aspect ratio. Also, rotations don't interrupt the video, which keeps playing without problems.

Everything seems fine, but... on my HTC Legend when you rotate back to portrait, the video is corrupted, and instead of showing full screen it is displayed at its native pixel size. But rotating again to landscape works and is shown perfectly. Any ideas why? Unfortunately I don't have more hardware to test this on and I've run out of ideas to test.

You can get the full example source code from https://github.com/gradha/Android-video-stream-rotation. Here are screen captures of me opening the application, rotating to landscape, touching the screen to display the video controls, then rotating back to portrait to see the corruption.

解决方案

In the source code at https://github.com/gradha/Android-video-stream-rotation. you added the comment:

Since we specified in the AndroidManifest.xml that we want to handle our own orientation changes, we resize the screen in function of being portrait or landscape.

From the source code AndroidManifest.xml

android:configChanges="orientation|screenSize"

So, if you add this attribute to the activity element in the manifest, I would interpret that as the activity will handle all the orientation changes? not you?

From Android Developers

To declare that your activity handles a configuration change, edit the appropriate activity element in your manifest file to include the android:configChanges attribute... more

So you should not need to:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

I created a test project to check if this was the case:

Rotating Video Stream Example: https://github.com/TouchBoarder/RotatingVideoStream

My conclusion: I did not need to overide the "onConfigurationChanged" in the activity to display the video correct in both portrait and landscape, and the video keeps playing on rotation changes.

Feel free to improve and use the code:)

这篇关于旋转回纵向时避免 Android VideoView 损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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