24. メディアソース一覧 Chrome
function getChromeMediaSource() {
MediaStreamTrack.getSources(function(sourceInfos) {
for (var i = 0; i != sourceInfos.length; ++i) {
var sourceInfo = sourceInfos[i];
if (sourceInfo.kind === 'audio') {
var id = sourceInfo.id;
var label = sourceInfo.label || 'microphone'; // label is available for https
// 適宜処理する
}
else if (sourceInfo.kind === 'video') {
var id = sourceInfo.id;
var label = sourceInfo.label || 'camera'; // label is available for https
} else {
console.log('Some other kind of source: ', sourceInfo);
}
}
});
25
25. デバイス一覧Firefox, Edge
function getDevices() {
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
console.log(device.kind + ": " + device.label + " id = " + device.deviceId);
if (device.kind === 'audioinput') {
var id = device.deviceId;
var label = device.label || 'microphone'; // label is available for specific domain with https
// 適宜処理する
}
else if (device.kind === 'videoinput') {
var id = device.deviceId;
var label = device.label || 'camera'; // label is available for specific domain with https
// 適宜処理する
}
});
})
.catch(function(err) {
console.log(err.name + ": " + error.message);
});
}
26