旋转回肖像时,应避免的Andr​​oid VideoView腐败 [英] Avoid Android VideoView corruption when rotating back to portrait

查看:268
本文介绍了旋转回肖像时,应避免的Andr​​oid VideoView腐败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地写一个有限的视频播放器能够从互联网上查看名为.3gp文件。视频将显示为中心全屏,保持视频宽高比。此外,旋转不中断的视频,这使打没有问题。

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.

一切似乎都很好,但是......我的HTC传奇,当你旋转回肖像,视频被损坏,而不是显示全屏幕则显示在其原生像素大小。但同样旋转,以景观工程和完美显示。任何想法,为什么?不幸的是,我没有更多的硬件来测试这一点,我已经江郎才尽了测试。

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.

您可以得到完整的示例源$ C ​​$ C <一个href="https://github.com/gradha/Android-video-stream-rotation">https://github.com/gradha/Android-video-stream-rotation.下面是我的屏幕捕获打开应用程序,旋转景观,触摸屏幕以显示视频控件,然后旋转回纵向看腐败。

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.

推荐答案

在源$ C ​​$ C处的 https://github.com/gradha/Android-video-stream-rotation 。你所添加的注释:

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

由于我们在指定的   AndroidManifest.xml中的我们要处理我们自己的方向   的变化,我们调整的是纵向屏幕在功能上或   景观。

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.

从C AndroidManifest.xml中源$ C ​​$

From the source code AndroidManifest.xml

android:configChanges="orientation|screenSize"

所以,如果你在清单中添加这个属性的活动要素,我会除preT,作为该活动将处理所有的方向变化?不是吗?

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?

从Android开发者

From Android Developers

要声明,您的活动处理更改配置,编辑   在清单文件适当的活动元素包括:   机器人:configChanges属性... 详情

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

所以,你应该的不可以需要:

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

我创建了一个测试项目来检查,如果是这样的话:

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

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

我的结论: 我没有必要在此改变onConfigurationChanged活动中显示视频的纵向和横向正确的,视频不断播放的旋转变化。

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.

随意提高和使用code:)

Feel free to improve and use the code:)

这篇关于旋转回肖像时,应避免的Andr​​oid VideoView腐败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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