private void switchCamera(final MenuItem item) { if (cameraState == CameraState.DISABLED_FROM_USER) { return; } cameraToggle.setEnabled(false); conversationFragmentCallbackListener.onSwitchCamera(new CameraVideoCapturer.CameraSwitchHandler() { @Override public void onCameraSwitchDone(boolean b) { Log.d(TAG, "camera switched, bool = " + b); isCurrentCameraFront = b; updateSwitchCameraIcon(item); toggleCameraInternal(); } @Override public void onCameraSwitchError(String s) { Log.d(TAG, "camera switch error " + s); Toaster.shortToast(getString(R.string.camera_swicth_failed) + s); cameraToggle.setEnabled(true); } }); }
private VideoCapturer getVideoCapturer(CameraVideoCapturer.CameraEventsHandler eventsHandler) { String[] cameraFacing = {"front", "back"}; int[] cameraIndex = {0, 1}; int[] cameraOrientation = {0, 90, 180, 270}; for (String facing : cameraFacing) { for (int index : cameraIndex) { for (int orientation : cameraOrientation) { String name = "Camera " + index + ", Facing " + facing + ", Orientation " + orientation; VideoCapturer capturer = VideoCapturerAndroid.create(name, eventsHandler); if (capturer != null) { Log.d("Using camera: ", name); return capturer; } } } } throw new RuntimeException("Failed to open capture"); }
/** * Create the video capturer * * @param cameraName the selected camera name * @return the video capturer */ private CameraVideoCapturer createVideoCapturer(String cameraName) { CameraVideoCapturer cameraVideoCapturer = null; CameraEnumerator camerasEnumerator = getCameraEnumerator(mContext); final String[] deviceNames = camerasEnumerator.getDeviceNames(); if ((null != deviceNames) && (deviceNames.length > 0)) { for (String name : deviceNames) { if (name.equals(cameraName)) { cameraVideoCapturer = camerasEnumerator.createCapturer(name, null); if (null != cameraVideoCapturer) { break; } } } if (null == cameraVideoCapturer) { cameraVideoCapturer = camerasEnumerator.createCapturer(deviceNames[0], null); } } return cameraVideoCapturer; }
private void switchCameraInternal() { if (videoCapturer instanceof CameraVideoCapturer) { if (!videoCallEnabled || isError || videoCapturer == null) { Log.e(TAG, "Failed to switch camera. Video: " + videoCallEnabled + ". Error : " + isError); return; // No video is sent or only one camera is available or error happened. } Log.d(TAG, "Switch camera"); CameraVideoCapturer cameraVideoCapturer = (CameraVideoCapturer) videoCapturer; cameraVideoCapturer.switchCamera(null); } else { Log.d(TAG, "Will not switch camera, video caputurer is not a camera"); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { QBRTCSession currentSession = ((CallActivity) getActivity()).getCurrentSession(); if (currentSession == null) { return super.onOptionsItemSelected(item); } final QBMediaStreamManager mediaStreamManager = currentSession.getMediaStreamManager(); if (mediaStreamManager == null) { return super.onOptionsItemSelected(item); } switch (item.getItemId()) { case R.id.switch_camera_toggle: mediaStreamManager.switchCameraInput(new CameraVideoCapturer.CameraSwitchHandler() { @Override public void onCameraSwitchDone(boolean b) { isFrontCameraSelected = b; toggleCameraInternal(); } @Override public void onCameraSwitchError(String s) { } }); break; case R.id.switch_speaker_toggle: toggleAudioOutput(); break; default: return super.onOptionsItemSelected(item); } getActivity().invalidateOptionsMenu(); return super.onOptionsItemSelected(item); }
private void switchCameraInternal() { if (videoCapturer instanceof CameraVideoCapturer) { if (!videoCallEnabled || isError) { Log.e(TAG, "Failed to switch camera. Video: " + videoCallEnabled + ". Error : " + isError); return; // No video is sent or only one camera is available or error happened. } Log.d(TAG, "Switch camera"); CameraVideoCapturer cameraVideoCapturer = (CameraVideoCapturer) videoCapturer; cameraVideoCapturer.switchCamera(null); } else { Log.d(TAG, "Will not switch camera, video caputurer is not a camera"); } }
@Override public void onSwitchCamera(CameraVideoCapturer.CameraSwitchHandler cameraSwitchHandler) { ((QBRTCCameraVideoCapturer)(currentSession.getMediaStreamManager().getVideoCapturer())) .switchCamera(cameraSwitchHandler); }
public void switchCamera() { if (mVideoCapturer instanceof CameraVideoCapturer) { ((CameraVideoCapturer) mVideoCapturer).switchCamera(null); } }
void onSwitchCamera(CameraVideoCapturer.CameraSwitchHandler cameraSwitchHandler);