[Android WebRTC] How to switch camera while call is active.

97 views
Skip to first unread message

Albert Devesa Triscon

unread,
Jul 2, 2014, 6:57:29 AM7/2/14
to discuss...@googlegroups.com
Hi,
I'm developing a Android WebRTC application based on AppRTCDemo and I wanted to switch camera while call is active. What I have done without sucess was removeStream of the peer connection, then get the new VideoCapturer from the other camera and addStream to the peer. Here I leave you the code:








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


        }


When I'm about to get the new VideoCapturer the app crashes. I think I can't get the new VideoCapturer because I have to get rid of the actual VideoCapturer (which I don't know how to do it).

Does anyone know how to solve it?

Thanks,
Albert

Albert Devesa Triscon

unread,
Jul 2, 2014, 2:43:13 PM7/2/14
to discuss...@googlegroups.com
I forgot to publish the getVideoCapturer method:
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");
}


Reply all
Reply to author
Forward
0 new messages