android - 旋转回纵向时避免 Android VideoView 损坏

标签 android corruption android-videoview screen-rotation

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

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

您可以从https://github.com/gradha/Android-video-stream-rotation 获得完整的示例源代码。 .以下是我打开应用程序、旋转到横向、触摸屏幕以显示视频控件、然后旋转回纵向以查看损坏情况的屏幕截图。 video started ok in portrait

on landscape the video works fine too

but now going back to portrait always shows corruption

最佳答案

源代码位于 https://github.com/gradha/Android-video-stream-rotation .你添加了评论:

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.

来自源码AndroidManifest.xml

android:configChanges="orientation|screenSize"

那么,如果您将此属性添加到 list 中的 Activity 元素,我会解释为 Activity 将处理所有方向更改吗?不是你吗?

来自 Android 开发者

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);
}

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

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

我的结论: 我无需覆盖 Activity 中的“onConfigurationChanged”即可正确显示纵向和横向视频,并且视频会在旋转变化时继续播放。

随时改进和使用代码:)

关于android - 旋转回纵向时避免 Android VideoView 损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6524659/

相关文章:

android - 在 Android Studio 中全局设置 Android NDK

java - 如何使数组大小取决于文本文件大小?

git - 修复从提交到提交的 git 断开的链接

Python ftplib 损坏文件?

database - 如何恢复损坏的 SQLite3 数据库?

android - 无法让 Vitamio VideoView 播放普通 Android VideoView 会播放的视频文件

java - 如何从 Android 应用程序中的按钮获取文本

android - 在 Eclipse 中编译时出错

android - 动态壁纸中的 VideoView?

android - VideoView和分步播放(逐帧)