我在 Android 中使用 SurfaceView
播放视频。
每当我旋转设备并且屏幕改变方向时,视频就会从头开始播放。
我希望视频在屏幕旋转时继续播放。
请指导我。
最佳答案
将其添加到您的 Manifest.xml 文件中。
android:configChanges="orientation"
你可以使用它来相应地设置高度和宽度等
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//Todo
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
// Todo
}
}
Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
关于android - 每当更改设备方向时,SurfaceView 都会重新启动视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23930437/