Search code examples
javascriptmediarecordergetusermedia

MediaRecorder Alternatives


Ive been playing about with MediaRecorder to save a MediaStream that has been created by getUserMedia. I'm really happy with the results, however I need something similar that has better cross browser support.

Here is some sample code for how I'm using MediaRecorder (just to give you some context):

var mediaRec;
navigator.getUserMedia({
    audio:true
},function(stream){
    mediaRec=new MediaRecorder(stream);
    mediaRec.start(10000);
    mediaRec.ondataavailable=function(e){

    };
},function(err){});

It seems that MediaRecorder only works in the Firefox browser and the Firefox OS.

However MediaRecorder is part of the W3C Specification, and Google Chrome has stated it intends to support it in a future release, but what options do I have in the meantime?

I know that plug ins such as Flash and Silverlight can achieve the same thing that MediaRecorder performs, but what I need is a javascript solution.

Can anyone help?


Solution

  • All the other options that are available will be utilizing high-level APIs and implemented at the Browser/JavaScript level. Thus, none will really be comparable to the MediaRecorder API provided by Firefox as it is integrated into the browser and has the benefit of being "lower level" in the browser's implementation.

    One option I know that works for sure(though utilizes the Web Audio API) is Matt Diamond's Recorderjs.

    And Example using Recorderjs taken from Matt's github.

      var audio_context;
      var recorder;
    
      function startUserMedia(stream) {
        var input = audio_context.createMediaStreamSource(stream);
    
        input.connect(audio_context.destination);
    
        recorder = new Recorder(input);
      }
    
      function startRecording() {
        recorder.record();
      }
    
      function stopRecording(button) {
        recorder.stop();
        createDownloadLink();
    
        recorder.clear();
      }
    
      function createDownloadLink() {
        recorder.exportWAV(function(blob) {
          var url = URL.createObjectURL(blob);
          var li = document.createElement('li');
          var au = document.createElement('audio');
          var hf = document.createElement('a');
    
          au.controls = true;
          au.src = url;
          hf.href = url;
          hf.download = new Date().toISOString() + '.wav';
          hf.innerHTML = hf.download;
          li.appendChild(au);
          li.appendChild(hf);
          recordingslist.appendChild(li);
        });
      }
    
      window.onload = function init() {
        try {
          // webkit shim
          window.AudioContext = window.AudioContext || window.webkitAudioContext;
          navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
          window.URL = window.URL || window.webkitURL;
    
          audio_context = new AudioContext;
    
        navigator.getUserMedia({audio: true}, startUserMedia, function(e) {
          console.log('No live audio input: ' + e);
        });