Last active
February 21, 2021 01:51
-
-
Save hadpro24/5392867fee1b3bc1746920b4fc3a59a1 to your computer and use it in GitHub Desktop.
This file contains 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
<script type="text/javascript"> | |
var recorder; | |
const record = async() =>{ | |
let localStream | |
try { | |
localStream = await navigator.mediaDevices.getUserMedia({ | |
audio: true | |
}) | |
} catch (error) { | |
console.log(error) | |
} | |
recorder = new MediaRecorder(localStream); | |
recorder.start(); | |
} | |
const stopRecord = () => { | |
// | |
recorder.stop(); | |
recorder.ondataavailable = function(e) { | |
var url = URL.createObjectURL(e.data); | |
var preview = document.querySelector('audio'); | |
preview.autoplay = true; | |
preview.src = url; | |
// http call | |
console.log(e.data, url); | |
}; | |
} | |
document.querySelector('button').addEventListener('mouseup', stopRecord); | |
document.querySelector('button').addEventListener('mousedown', record); | |
/// stop record | |
stream.getTracks().forEach(function(track) { | |
track.stop(); | |
}); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment