I could not find any answer yet to my question after hours. I've been able recording from microphone only. What i want is, Recording from the speakers (Internal). The idea is a virtual piano which i recently working on it, And users should be able to record what they play.
Here is my code:
const record = ()=> {
console.log('recording started...')
navigator.mediaDevices.getUserMedia({audio:true}).then( stream => {
const MEDIA_RECORDER = new MediaRecorder(stream);
MEDIA_RECORDER.start();
const AUDIO_CHUNKS = [];
MEDIA_RECORDER.addEventListener('dataavailable',e => {
AUDIO_CHUNKS.push(e.data);
})
MEDIA_RECORDER.addEventListener('stop',() =>
{
const AUDIO_BLOB = new Blob(AUDIO_CHUNKS);
const AUDIO_URL = URL.createObjectURL(AUDIO_BLOB);
const AUDIO = new Audio(AUDIO_URL);
AUDIO.play();
})
setTimeout(()=>{
MEDIA_RECORDER.stop();
alert('Recording done!')
},3000)
})
}
Any idea how to accomplish it? Any answer is appreciated.