Enable rear camera with HTML5

前端 未结 5 1697
失恋的感觉
失恋的感觉 2020-11-28 03:02

I\'m working on a project with MVC ASP.Net 4 HTML5 (default browser is google-chrome v29.0.1547.57) I can interact with these tools and take photographs but only with front

5条回答
  •  庸人自扰
    2020-11-28 03:14

    In Chrome on my Samsung S8 I can use "facingMode"="environment" to take video from the 'rear camera'. The default seems to be "user" (the 'front' camera)

    in TypeScript:

        const video = document.getElementById("video");
        const constraints = {
            advanced: [{
                facingMode: "environment"
            }]
        };
        navigator.mediaDevices
            .getUserMedia({
                video: constraints
            })
            .then((stream) => {
                video.src = window.URL.createObjectURL(stream);
                video.play();
            });
    

    ref: MediaTrackConstraints/facingMode

提交回复
热议问题