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

标签 android video surfaceview

我在 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).

(复制自:nmr,引用docs)

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

相关文章:

Android:如何在已经显示 Camara 预览的 Surfaceview 上绘图

安卓开发: Combining small tiles/bitmaps into one bitmap

java - 交易导致 Activity 召回 Firebase Android

java - 应用低通滤波器

shell - FFMPEG,.txt 文件中的倒数第二张图像未显示在视频中

javascript - 单击关闭或外部单击时的 Bootstrap 模式不会停止 youTube 视频

Android 在后台使用相机表面 View 播放视频

android - 平台证书”在 root 的 android 手机中

android - SetTexture 和 Sprites 没有按预期工作! (LibGDX)

html - 响应式视频未按预期调整