RecordRTC:如何在Chrome中捕获音频媒体流?

时间:2015-04-17 21:55:05

标签: google-chrome-extension webrtc audio-recording mediastreamsource

所以我一直在尝试使用RecordRTC来录制来自标签的音频。 RecordRTC需要作为参数传递Mediastream,这需要从页面捕获流。在这里链接了一些代码,试图捕获该流但无法使其工作。还将链接我的github存储库:https://github.com/laotsunami/soundbyte

请帮忙!

var constraints = {audio: true, video: false};
var bg = chrome.extension.getBackgroundPage();
bg.console.log("started");


document.addEventListener('DOMContentLoaded', function() {


function successCallback(stream) {
  bg.console.log('entered success callback')
  window.stream = stream; // stream available to console
  if (window.URL) {
    audio.src = window.URL.createObjectURL(stream);
  } else {
    audio.src = stream;
  }
}

function errorCallback(error){
  bg.console.log('navigator.getUserMedia error: ', error);
}

navigator.getUserMedia(constraints, successCallback, errorCallback);

  // bg.console.log(mediaStream);

  var startButton = document.getElementById('startButton');
  startButton.addEventListener('click', function() {
    bg.console.log('Clicked Start Button');

    
    var recordRTC = RecordRTC(mediaStream); 
    bg.console.log('Clicked Start Button');
    recordRTC.startRecording(function() {
      bg.console.log('recording started');
    }); 
    bg.console.log("didn't crash");
  });

  var stopButton = document.getElementById('stopButton');
  stopButton.addEventListener('click', function() {
    bg.console.log('Clicked Stop Button');

    recordRTC.stopRecording(function(audioURL) { 
          bg.console.log('stopped recording');
          mediaElement.src = audioURL;
          bg.console.log(audioURL); 
      });
  });

});

0 个答案:

没有答案