gpt4 book ai didi

android - 每当更改设备方向时,SurfaceView 都会重新启动视频

转载 作者:行者123 更新时间:2023-11-30 02:52:21 25 4
gpt4 key购买 nike

我在 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 landscapeorientation. Thus, if you want to prevent runtime restarts due toorientation change when developing for API level 13 or higher (asdeclared by the minSdkVersion and targetSdkVersion attributes), youmust include the "screenSize" value in addition to the "orientation"value. That is, you must decalareandroid:configChanges="orientation|screenSize". However, if yourapplication targets API level 12 or lower, then your activity alwayshandles this configuration change itself (this configuration changedoes not restart your activity, even when running on an Android 3.2 orhigher device).

(复制自:nmr,引用docs)

关于android - 每当更改设备方向时,SurfaceView 都会重新启动视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23930437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com