Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mediastreamtrack.getsources not supported in firefox, how to do the equivalent

is there an equivalent way to get the list of video devices connected to the PC? I have an external webcam connection in addition to the build-in one.

mediastreamtrack.getsources is working in chrome but firefox reported "TypeError: MediaStreamTrack.getSources is not a function". I am running firefox version 25.0.1

Thanks!

like image 385
user2868949 Avatar asked Nov 21 '13 01:11

user2868949


2 Answers

Please use below-mentioned code. It is working properly giving all audio and video devices list.

navigator.mediaDevices.enumerateDevices()
        .then(function (devices) {
            devices.forEach(function (device) {
                var option = document.createElement('option');
                option.value = device.deviceId;
                if (device.kind === 'videoinput') {
                    option.text = device.label || 'camera' + (videoSelect.length + 1);
                    videoSelect.appendChild(option);
                } else if (device.kind == 'audioinput') {
                    option.text = device.label || 'mic' + (audioSelect.length + 1);
                    audioSelect.appendChild(option);
                }
            });
        })
        .catch(function (err) {
            console.log(err.name + ": " + err.message);
        });
like image 55
Pardip Bhatti Avatar answered Nov 12 '22 07:11

Pardip Bhatti


MediaDevices.enumerateDevices() is now supported by Firefox and Chrome.

like image 2
Sam Dutton Avatar answered Nov 12 '22 08:11

Sam Dutton