Created
October 4, 2018 21:24
-
-
Save jherico/a5c54daa12fbb8512578c753bd30bedd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(deviceName) { | |
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(function(mediaStream) { | |
navigator.mediaDevices.enumerateDevices().then(function(devices) { | |
devices.forEach(function(device) { | |
if (device.kind == "audiooutput") { | |
if (device.label == deviceName){ | |
console.log("Changing HTML audio output to device " + device.label); | |
var deviceId = device.deviceId; | |
var videos = document.getElementsByTagName("video"); | |
for (var i = 0; i < videos.length; i++){ | |
videos[i].setSinkId(deviceId); | |
} | |
var audios = document.getElementsByTagName("audio"); | |
for (var i = 0; i < audios.length; i++){ | |
audios[i].setSinkId(deviceId); | |
} | |
} | |
} | |
}); | |
}).catch(function(err) { | |
console.log("Error getting media devices"+ err.name + ": " + err.message); | |
}); | |
}).catch(function(err) { | |
console.log("Error getting user media"+ err.name + ": " + err.message); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment