hasMicrophone() {
? ? ? return navigator.mediaDevices.getUserMedia({ audio: true })
? ? ? ? .then(function(stream) {
? ? ? ? ? // 檢查stream中是否有audio track
? ? ? ? ? return stream.getAudioTracks().length > 0;
? ? ? ? })
? ? ? ? .catch(function(error) {
? ? ? ? ? console.log('Microphone check error:', error);
? ? ? ? ? return false;
? ? ? ? });
? ? }
? ? this.hasMicrophone().then(function(hasMic) {
? ? ? if (hasMic) {
? ? ? ? console.log('設(shè)備有麥克風(fēng),且可用。');
? ? ? } else {
? ? ? ? console.log('設(shè)備沒有麥克風(fēng),或者不可用。');
? ? ? }
? ? });