Skip to content

Instantly share code, notes, and snippets.

@larryyangsen
Created August 4, 2018 11:42
Show Gist options
  • Save larryyangsen/e0b118fde0a1e408caf386bb19b3024b to your computer and use it in GitHub Desktop.
Save larryyangsen/e0b118fde0a1e408caf386bb19b3024b to your computer and use it in GitHub Desktop.
html get user media
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Recording</title>
</head>
<body>
<div>
<video id="player" controls></video>
</div>
<script>
(async () => {
const player = document.getElementById('player');
const bufferSize = 4096;
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: true
});
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioContext = new AudioContext;
const sourceNode = audioContext.createMediaStreamSource(stream);
const processor = audioContext.createScriptProcessor(bufferSize, 1, 1);
player.srcObject = stream;
processor.onaudioprocess = e => {
console.log(e)
};
processor.connect(audioContext.destination);
sourceNode.connect(processor)
})()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment