Motorola Moto G — Unable to access camera 2 times using web application

  • Replies:6
  • OpenNot stickiedUnanswered
  • Forum posts: 4

Jan 21, 2020, 5:07:38 AM via Website

Hi..........
I am having a problem to access the web camera 2 time, when i am access it first time its working fine but when i want to access second time on same web application its getting error.

Reply
  • Forum posts: 1,020

Jan 21, 2020, 6:08:00 AM via Website

could you be a bit more clear please?

Helpful?
Reply
  • Forum posts: 4

Jan 21, 2020, 6:13:06 AM via Website

Actually i am developer i am working on video streaming and Webrtc, so i made a link for our website in which i am using camera two time where, when i called it first time its working and when i am calling it second time i am not able to access it whereas it working fine on some mobiles and window system.

Helpful?
Reply
  • Forum posts: 1,263

Jan 21, 2020, 8:20:42 AM via Website

What's the error message showed? Perhaps posting some codes about accessing camera will be more helpful.

Download size < 0.07 MB. But also Accurate, Ad-Free & Full-Free.
The minimalist app available on Google Play https://goo.gl/ws42fN
Your 5-star is appreciated. Blog : https://okblackcafe.blogspot.com

Helpful?
Reply
  • Forum posts: 4

Jan 21, 2020, 8:24:42 AM via Website

i am getting below error when i am access it second time but its working fine on some devices.

image

Helpful?
Reply
  • Forum posts: 4

Jan 21, 2020, 11:47:47 AM via Website

i used this code its working on system but not in motorola device

navigator.getUserMedia(constraints,
function(stream) {
consentCB(false);
myStream = stream;
// Create PeerConnection
var pc_config = iceServers;
var pc_constraints = {
"optional": [{"DtlsSrtpKeyAgreement": true}]
};
//pc connection details
//pc = new RTCPeerConnection(iceServers, pc_constraints);
pc = new RTCPeerConnection({
"iceServers": iceServers,
pc_constraints,
});

                            window.pc = pc;  
            pc.onicecandidate = function(event) {
                // Trickle candidate (or the end of the gathering process)
                var candidate = null;
                if(event.candidate === null) {
                    candidate = { completed: true };
                } else {
                    candidate = {
                        candidate: event.candidate.candidate,
                        sdpMid: event.candidate.sdpMid,
                        sdpMLineIndex: event.candidate.sdpMLineIndex
                    };
                }
                console.log("Trickling candidate:", candidate);
                console.log(iceServers);
                var msg = {
                    monet: "trickle",
                    id: randomString(16),
                    payload: {
                        candidate: candidate
                    }
                };
                sendMsg(msg);
            };
            pc.addStream(stream);
            var previewCB = (typeof that.callbacks["preview"] == "function") ? that.callbacks["preview"] : MonetDemo.noop;
            previewCB(stream);
            // Create offer
            pc.createOffer(
                function(offer) {
                    if(sdpSent === true) {
                        console.log("Offer already sent, not sending it again");
                        return;
                    }
                    sdpSent = true;
                    pc.setLocalDescription(offer);
                    var jsep = {
                        type: offer.type,
                        sdp: offer.sdp
                    };
                    // Send the open request
                    var msg = {
                        monet: "open",
                        id: randomString(16),
                        payload: {
                            jsep: jsep
                        }
                    };
                    sendMsg(msg, function response(result) {
                        console.log("Got answer to offer");
                        if(result["monet"] === "error") {
                            that.hangup();
                            console.log(result["payload"]["reason"]);
                            callback(result["payload"]["reason"]);
                            return;
                        }
                        var remoteJsep = result["payload"]["jsep"];
                        console.log(remoteJsep);
                        pc.setRemoteDescription(
                            new RTCSessionDescription(remoteJsep),
                            function() {
                                console.log("Remote description accepted!");
                                callback();
                            }, function(error) {
                                that.hangup();
                                console.log(error);
                                callback(error);
                            });
                    });
                }, function(error) {
                    that.hangup();
                    console.log(error);
                    callback(error);
                });
        },
        function(error) {
            consentCB(false);
            console.log(error);
            callback(error);
            alert("Please allow camera to processed or check your camera setting");
            window.location.reload();
        });
Helpful?
Reply
Recommended articles