我正在尝试使用 MediaDevice API 响应设备更改事件,如下所示
_trackDeviceChange: function () {
var e = this
navigator.mediaDevices.ondevicechange = function () {
navigator.mediaDevices.enumerateDevices().then(function (n) {
e.get('allVideoSourceDevices').clear(),
e.get('allAudioSourceDevices').clear(),
e.get('allVideoSourceDevices').pushObjects(t.default.filter(n, [
'kind',
'videoinput'
])), e.get('allAudioSourceDevices').pushObjects(t.default.filter(n, [
'kind',
'audioinput'
])), e.get('videoSourceDevice') && !t.default.find(n, {
deviceId: e.get('videoSourceDevice.deviceId'),
kind: 'videoinput',
label: e.get('videoSourceDevice.label')
}) ? e.set('deviceNotFound', 'camera') : e.get('audioSourceDevice') && !t.default.find(n, {
deviceId: e.get('audioSourceDevice.deviceId'),
kind: 'audioinput',
label: e.get('audioSourceDevice.label')
}) && e.set('deviceNotFound', 'microphone')
})
}
}
它仅适用于不适用于 3.5m 插孔的 USB 设备