Android:pjsua2相机旋转问题

时间:2019-09-03 10:13:12

标签: android pjsip screen-rotation pjsua2

我正在使用pjsip库实现视频通话。 我面临的问题仅是正面模式的相机旋转。

这是我的代码:

val wm: WindowManager = this.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val display: Display
        val rotation: Int
        val orient: pjmedia_orient

        display = wm.defaultDisplay
        rotation = display.rotation
        println("Device orientation changed: $rotation")

        orient = when (rotation) {
            Surface.ROTATION_0   // Portrait
            -> pjmedia_orient.PJMEDIA_ORIENT_ROTATE_270DEG
            Surface.ROTATION_90  // Landscape, home button on the right
            -> pjmedia_orient.PJMEDIA_ORIENT_ROTATE_180DEG
            Surface.ROTATION_180 -> pjmedia_orient.PJMEDIA_ORIENT_ROTATE_90DEG
            Surface.ROTATION_270 // Landscape, home button on the left
            -> pjmedia_orient.PJMEDIA_ORIENT_NATURAL
            else -> pjmedia_orient.PJMEDIA_ORIENT_UNKNOWN
        }

        if (MyApp.ep != null && SipManager.account != null) {
            try {
                val cfg = SipManager.account?.cfg
                val cap_dev = cfg?.videoConfig?.defaultCaptureDevice
                MyApp.ep?.vidDevManager()?.setCaptureOrient(cap_dev!!, orient,
                        true)
            } catch (e: Exception) {
                println(e)
            }

        }

对于ROTATION_0和ROTATION_180,这是正确的。 但是,当我将设备旋转到横向模式时,它会以相反的方向旋转。

提前谢谢!

0 个答案:

没有答案
相关问题