Capture system sound from browser

前端 未结 1 2090
轻奢々
轻奢々 2021-02-20 17:59

I am trying to build a web app that captures both local and remote audios from a webrtc call, but I can`t record the remote audio(using recordRTC). I was wondering if I could ca

相关标签:
1条回答
  • 2021-02-20 18:24

    In Chrome, the chrome.desktopCapture extension API can be used to capture the screen, which includes system audio (but only on Windows and Chrome OS and without plans for OS X or Linux). E.g.

    chrome.desktopCapture.chooseDesktopMedia([
        'screen', 'window' // ('tab' is not supported; use chrome.tabCapture instead)
    ], function(streamId) {
        navigator.webkitGetUserMedia({
            audio: {
                mandatory: {
                    chromeMediaSource: 'system',
                    chromeMediaSourceId: streamId
                }
            },
            video: false, // We only want audio for now.
        }, function(stream) {
            // Do what you want with this MediaStream.
        }, function(error) {
            // Handle error
        });
    });
    

    I'm not sure whether Firefox can capture system sound, but at the very least it is capable of capturing some output (tab/window/browser/OS?). First you need to visit about:config and set media.getusermedia.audiocapture.enabled to true (this could be automated through a Firefox add-on). Then the stream can be captured as follows:

    navigator.mozGetUserMedia({
        audio: {
            mediaSource: 'audioCapture'
        },
        video: false, // Just being explicit, we only want audio for now
    }, function(stream) {
        // Do what you want with this MediaStream.
    }, function(error) {
        // Handle error
    });
    

    This was implemented in Firefox 42, at https://bugzilla.mozilla.org/show_bug.cgi?id=1156472

    0 讨论(0)
提交回复
热议问题