public void switchCamera(String cameraFacing, String height, String width){
Peer peer = peers.get(socketIDExt);
peer.pc.removeStream(lMS);
mListener.onRemoveLocalStream(lMS, peer.endPoint);
MediaConstraints videoConstraints = new MediaConstraints();
videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxHeight", height));
videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxWidth", width));
camera = getVideoCapturer(cameraFacing); //here I get the "Failed to open capturer" exception and the app crashes
//the code will go on here
}
private VideoCapturer getVideoCapturer(String cameraFacing) { int[] cameraIndex = { 0, 1 }; int[] cameraOrientation = { 0, 90, 180, 270 }; for (int index : cameraIndex) { for (int orientation : cameraOrientation) { String name = "Camera " + index + ", Facing " + cameraFacing + ", Orientation " + orientation; VideoCapturer capturer = VideoCapturer.create(name); if (capturer != null) { return capturer; } } } throw new RuntimeException("Failed to open capturer"); }