user2868949
user2868949

Reputation: 71

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!

Upvotes: 7

Views: 9683

Answers (4)

Pardip Bhatti
Pardip Bhatti

Reputation: 41

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);
        });

Upvotes: 2

Sam Dutton
Sam Dutton

Reputation: 15269

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

Upvotes: 2

Hanxue
Hanxue

Reputation: 12766

As of Firefox 34, MediaStreamTrack is now available.

https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack

Upvotes: -3

christi3k
christi3k

Reputation: 297

As of Nightly 28.0a1 Firefox does not have anything equivalent to Chrome's MediaStreamTrack.getSources. So, no, there is not currently a way to get a list of the local audio and video devices in Firefox.

I asked the developers working on Firefox's WebRTC implementation and they say this is a planned feature but no ETA on when it will land. You can view the irc log (scroll to 16:17) if you're curious.

Also, here's the relevant part in the draft W3C spec.

Upvotes: 1

Related Questions