本文共 890 字,大约阅读时间需要 2 分钟。
我从未使用过pjsip库,但从查看它们的
source code,这就是你的方法可以被重写的方式:
public class PjsipActivity extends Activity {
PjCamera pjCamera;
…
void switchCamera(boolean isFront) {
if (pjCamera == null) {
int w = (int) SipCallService.currentCall.vidPrev.getVideoWindow()
.getInfo().getSize().getW();
int h = (int) SipCallService.currentCall.vidPrev.getVideoWindow()
.getInfo().getSize().getH();
pjCamera = new PjCamera(0,mSurfaceCapture);
}
CameraInfo ci = new CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
Camera.getCameraInfo(i,ci);
if (isFront && ci.facing == CameraInfo.CAMERA_FACING_FRONT ||
!isFront && ci.facing == CameraInfo.CAMERA_FACING_BACK) {
if (pjCamera.SwitchDevice(i) == 0) {
return;
}
}
}
showToast("Error while switching camera");
}
}
请注意,此代码段不能解决预览大小问题.据我所知,PjCamera不支持动态改变宽度和高度.视频窗口的大小应该在会话建立之前分别在两个对等体之间协商.如果前置摄像头或后置摄像头不支持此预览大小,SwitchDevice()很可能会失败并返回代码-30,但它也可能会崩溃或无提示失败.
转载地址:https://blog.csdn.net/weixin_39610678/article/details/117577544 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!