5

Using the getUserMedia() API to use the camera. The problem I have is that it works on everything but iOS and iPad. I can snap a picture but I can't zoom. I saw this post but has no response. I'm looking at caniuse and the capabilities and from what I can tell Safari on both mobile and desktop shows it's supported. Any tips?

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
    navigator.mediaDevices.getUserMedia(videoConstraints)
    .then(stream => {

        setTimeout((evt) => {

            const track = stream.getVideoTracks()[0];
            const capabilities = track.getCapabilities();
            const settings = track.getSettings();

            if (('zoom' in capabilities)) {

                alert('zoom exists');
                const elemZoom = this.dom.select(`${this.el} #zoom-slider`);

                // Map zoom to a slider element.
                elemZoom.min = capabilities[`zoom`][`min`];
                elemZoom.max = capabilities[`zoom`][`max`];
                elemZoom.step = capabilities[`zoom`][`step`];
                elemZoom.value = settings[`zoom`];
                elemZoom.oninput = (event) => {
                    track.applyConstraints({
                        advanced: [{
                            zoom: event.target.value
                        }]
                    });
                }
                elemZoom.hidden = false;
            }

            elemVideo.srcObject = stream;


        }, 500);
    })
    .catch(err => {

    });
}
adviner
  • 3,295
  • 10
  • 35
  • 64

0 Answers0