mirror of
https://github.com/kou029w/chirimen-hands-on.git
synced 2025-01-18 08:05:05 +00:00
enumerateDevices() before getUserMedia()
This commit is contained in:
parent
d785ed14a1
commit
7ffb578066
1 changed files with 18 additions and 18 deletions
|
@ -9,6 +9,24 @@
|
|||
<div id="player"></div>
|
||||
<div id="devices"></div>
|
||||
<script type="module">
|
||||
const deviceId = location.hash.slice(1);
|
||||
const playerElement = document.getElementById("player");
|
||||
const videoElement = document.createElement("video");
|
||||
const srcObject = await navigator.mediaDevices.getUserMedia({
|
||||
video: {
|
||||
deviceId,
|
||||
},
|
||||
});
|
||||
|
||||
Object.assign(videoElement, {
|
||||
controls: "controls",
|
||||
autoplay: true,
|
||||
muted: true,
|
||||
srcObject,
|
||||
});
|
||||
|
||||
playerElement.append(videoElement);
|
||||
|
||||
const devicesElement = document.getElementById("devices");
|
||||
const devices = (await navigator.mediaDevices.enumerateDevices()).filter(
|
||||
({ kind }) => kind === "videoinput",
|
||||
|
@ -27,24 +45,6 @@
|
|||
}
|
||||
|
||||
window.onhashchange = () => location.reload();
|
||||
|
||||
const deviceId = location.hash.slice(1);
|
||||
const playerElement = document.getElementById("player");
|
||||
const videoElement = document.createElement("video");
|
||||
const srcObject = await navigator.mediaDevices.getUserMedia({
|
||||
video: {
|
||||
deviceId,
|
||||
},
|
||||
});
|
||||
|
||||
Object.assign(videoElement, {
|
||||
controls: "controls",
|
||||
autoplay: true,
|
||||
muted: true,
|
||||
srcObject,
|
||||
});
|
||||
|
||||
playerElement.append(videoElement);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue