muaz-khan / RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
https://www.webrtc-experiment.com/RecordRTC/
MIT License
6.59k stars 1.76k forks source link

Can not record audio #297

Closed mbellezi closed 7 years ago

mbellezi commented 7 years ago

If I check "Record Selected Tab only" is the only way to record audio but I can not hear it while recording. Is there a way to listen and record? There is no "Tab capture API" option. Please help!

nuthinking commented 7 years ago

I would love to know if there is a solution for recording audio while playing it too. Thanks!

muaz-khan commented 7 years ago

Please install chrome extension and select "Full Screen + System Audio". (it will be using desktopCapture instead)

PS. tabCapture mutes audios; and we didn't found any fix/hack yet. That's why desktopCaptue can be a good alternative.

muaz-khan commented 7 years ago

Solution for tabCapture API:

Create an HTML5 audio element, set source (i.e. SRC) based on tabCapture stream, and play the audio element during recording. Snippet:

function hackForTabCaptureStream(tabStream) {
    var audio = document.createElement('audio');
    audio.muted = false; // MUST NOT be MUTED
    audio.volume = 1; // MUST be full volume
    audio.src = URL.createObjectURL(tabStream);
    audio.play(); // MUST be playing during recording
}

Fixed #288 as well.

michaelsmoody commented 4 years ago

Good afternoon,

This still seems to be a present issue in the current May 2020 release on the extension web store. Or do I need to continue using the https://github.com/muaz-khan/RecordRTC/issues/297#issuecomment-316267459 recommendation?

Michael

uffou commented 4 years ago

You can create a new audio stream and combine both streams like so

let stream
if (navigator.mediaDevices.getDisplayMedia) {
    stream = await navigator.mediaDevices.getDisplayMedia(displaymediastreamconstraints).catch((event) => {
        console.error(event)
        // store.error = 'Permission denied!'
    })
} else {
    stream = await navigator.getDisplayMedia(displaymediastreamconstraints).catch((event) => {
        console.error(event)
        // store.error = 'Permission denied!'
    })
}

const [videoTrack] = stream.getVideoTracks()
const audioStream = await navigator.mediaDevices.getUserMedia({ audio: true }).catch((event) => {
    throw event
})
const [audioTrack] = audioStream.getAudioTracks()
// displayStream.addTrack(audioTrack); // do stuff
// or
store.stream = new MediaStream([videoTrack, audioTrack]) // do stuff
store.recorder = new RecordRTCPromisesHandler(store.stream, {
    // audio, video, canvas, gif
    type: 'video',
})