I need to record audio and stream live, I discovered that with HTML5 and JavaScript / jQuery it is possible and that it has plugins that can help me. I'm using one of them, the MediaStreamRecorder and I'm recording and streaming live to myself, but I can not broadcast to anyone, anyone knows How do I make this transmission? Probably using socket? Where is the file being recorded? How to send the file to the server in real time?
EDIT: How to send blob in real time to server?
LINK NO JSFIDDLE: link
Code used (the plugin is in github at this link: MediaStreamRecorder ):
<script src="//www.webrtc-experiment.com/MediaStreamRecorder.js"> </script>
<h1>
Audio Recording using <a href="https://github.com/streamproc/MediaStreamRecorder"
target="_blank">MediaStreamRecorder</a>
</h1>
<div id="audios-container">
</div>
<script>
var mediaConstraints = { audio: true };
navigator.getUserMedia(mediaConstraints, onMediaSuccess, onMediaError);
function onMediaSuccess(stream) {
var audio = document.createElement('audio');
audio = mergeProps(audio, {
controls: true,
src: URL.createObjectURL(stream)
});
audio.play();
audiosContainer.appendChild(audio);
audiosContainer.appendChild(document.createElement('hr'));
var mediaRecorder = new MediaStreamRecorder(stream);
mediaRecorder.mimeType = 'audio/ogg';
mediaRecorder.ondataavailable = function(blob) {
var a = document.createElement('a');
a.target = '_blank';
a.innerHTML = 'Open Recorded Audio No. ' + (index++);
a.href = URL.createObjectURL(blob);
audiosContainer.appendChild(a);
audiosContainer.appendChild(document.createElement('hr'));
};
// get blob after each 5 second!
mediaRecorder.start(5 * 1000);
}
function onMediaError(e) {
console.error('media error', e);
}
var audiosContainer = document.getElementById('audios-container');
var index = 1;
</script