android - 在 pjsip android 中从前向后切换相机

标签 android android-camera surfaceview sip pjsip

我正在开发 pjsip 视频通话应用程序。我想在通话中切换预览摄像头。

这是我正在尝试的代码。

private void switchCamera(boolean isFront) {
        try {
            int w = (int) SipCallService.currentCall.vidPrev.getVideoWindow()
                    .getInfo().getSize().getW();
            int h = (int) SipCallService.currentCall.vidPrev.getVideoWindow()
                    .getInfo().getSize().getH();
            if (isFront) {
                PjCamera camera = new PjCamera(0, w, h, 0, 0, 0,
                        mSurfaceCapture);
                camera.SwitchDevice(0);
            } else {
                PjCamera camera = new PjCamera(0, w, h, 0, 0, 0,
                        mSurfaceCapture);
                camera.SwitchDevice(1);
            }

        } catch (Exception e) {
            e.printStackTrace();
            showToast("Error while switching camera");
        }
    }

PjCamera是pjsip提供的类。

我无法使用上面的代码切换摄像头。

如果有任何其他方法,请指导我。

最佳答案

我使用这段代码在前置/后置摄像头之间切换。

    int cameraId = isFront? 1 :2;

    CallVidSetStreamParam callVidSetStreamParam = new CallVidSetStreamParam();
    callVidSetStreamParam.setCapDev(cameraId);
    try {
        sipCall.vidSetStream(pjsua_call_vid_strm_op.PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV, callVidSetStreamParam);
        result = true;
    } catch (Exception e) {
        e.printStackTrace();
    }

关于android - 在 pjsip android 中从前向后切换相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34593623/

相关文章:

android - CPU 处理相机图像

android - Camera.startPreview() 问题

android 录像 - RuntimeException : stop failed

android - 将 ImageView 放置在透明 SurfaceView 上

Android Volley 多个请求

android - 根据用户在配置 Activity 中的选择,在小部件中将 StateListDrawable 设置为 ImageButton/ImageView.backgroundDrawable

Android - 使相机预览半透明

android - SurfaceView相机预览: find camera preview size without stretch

java - 构造函数 Intent(DataCountUtilities, Class<DataCountService>) 未定义

android - 有没有办法在 Android 上以编程方式设置默认主页/启动器?