public CameraCapturerCompat(Context context, CameraCapturer.CameraSource cameraSource) { var camera2CapturerEventHandler = new Camera2CapturerEventHandler(this); camera2CapturerEventHandler.OnCameraSwitched += (sender, newCameraId) => { Log.Info(TAG, "onCameraSwitched: newCameraId = " + newCameraId); }; camera2CapturerEventHandler.OnError += (sender, args) => { Log.Error(TAG, args.P0.ToString()); }; camera2CapturerEventHandler.OnFirstFrameAvailable += (sender, args) => { Log.Info(TAG, "onFirstFrameAvailable"); }; if (Camera2Capturer.IsSupported(context)) { SetCameraPairs(context); _camera2Capturer = new Camera2Capturer(context, GetCameraId(cameraSource), camera2CapturerEventHandler.ListenerImplementor); } else { _camera1Capturer = new CameraCapturer(context, cameraSource); } }
private string GetCameraId(CameraCapturer.CameraSource cameraSource) { if (_frontCameraPair.Item1 == cameraSource) { return(_frontCameraPair.Item2); } return(_backCameraPair.Item2); }
public void SwitchCamera() { if (UsingCamera1()) { _camera1Capturer.SwitchCamera(); } else { CameraCapturer.CameraSource cameraSource = GetCameraSource(_camera2Capturer.CameraId); if (cameraSource == CameraCapturer.CameraSource.FrontCamera) { _camera2Capturer.SwitchCamera(_backCameraPair.Item2); } else { _camera2Capturer.SwitchCamera(_frontCameraPair.Item2); } } }
/* * The initial state when there is no active room. */ private void IntializeUi() { connectActionFab.SetImageDrawable(ContextCompat.GetDrawable(this, Resource.Drawable.ic_call_white_24px)); connectActionFab.Show(); //connectActionFab.SetOnClickListener(ConnectActionClickListener()); connectActionFab.Click += (sender, args) => { ShowConnectDialog(); }; switchCameraActionFab.Show(); //switchCameraActionFab.SetOnClickListener(SwitchCameraClickListener()); switchCameraActionFab.Click += (sender, args) => { if (cameraCapturerCompat != null) { CameraCapturer.CameraSource cameraSource = cameraCapturerCompat.GetCameraSource(); cameraCapturerCompat.SwitchCamera(); if (thumbnailVideoView.Visibility == ViewStates.Visible) { thumbnailVideoView.SetMirror(cameraSource == CameraCapturer.CameraSource.BackCamera); } else { primaryVideoView.SetMirror(cameraSource == CameraCapturer.CameraSource.BackCamera); } } }; localVideoActionFab.Show(); //localVideoActionFab.SetOnClickListener(LocalVideoClickListener()); localVideoActionFab.Click += (sender, args) => { /* * Enable/disable the local video track */ if (localVideoTrack != null) { bool enable = !localVideoTrack.IsEnabled; localVideoTrack.Enable(enable); int icon; if (enable) { icon = Resource.Drawable.ic_videocam_green_24px; switchCameraActionFab.Show(); } else { icon = Resource.Drawable.ic_videocam_off_red_24px; switchCameraActionFab.Hide(); } localVideoActionFab.SetImageDrawable(ContextCompat.GetDrawable(this, icon)); } }; muteActionFab.Show(); //muteActionFab.SetOnClickListener(MuteClickListener()); muteActionFab.Click += (sender, args) => { if (localAudioTrack != null) { bool enable = !localAudioTrack.IsEnabled; localAudioTrack.Enable(enable); int icon = enable ? Resource.Drawable.ic_mic_green_24px : Resource.Drawable.ic_mic_off_red_24px; muteActionFab.SetImageDrawable(ContextCompat.GetDrawable(this, icon)); } }; }