Подтвердить что ты не робот

Захват микрофона HTML5 останавливается через 5 секунд в Firefox

Я записываю аудио вход с микрофона с помощью функции getUserMedia(), отлично работает в хроме, но в режиме firefox звук исчезает через 5 секунд. Если я снова отправлю запрос на микрофон (без перезагрузки страницы), это произойдет. Вот код (я использовал http://updates.html5rocks.com/2012/09/Live-Web-Audio-Input-Enabled как руководство):

//getting the function depending on browser

navigator.getMedia = ( navigator.getUserMedia ||
                       navigator.webkitGetUserMedia ||
                       navigator.mozGetUserMedia ||
                       navigator.msGetUserMedia);

// success callback when requesting audio input stream
function gotAudioStream(stream) {
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    var audioContext = new AudioContext();

    // Create an AudioNode from the stream.
    var mediaStreamSource = audioContext.createMediaStreamSource( stream );

    // Connect it to the destination to hear yourself (or any other node for processing!)
    mediaStreamSource.connect( audioContext.destination );
}


function gotError(err) {
      alert("An error occured! " + err);
}


//when button clicked, browser asks a permission to access microphone

jQuery("#sound_on").click(function()
{
    navigator.getMedia({audio: true},gotAudioStream,gotError);
});

Любые идеи?


EDIT/UPDATE

Спасибо, csch, за ссылку. Обходной путь Карун Касэри работает!

context = new AudioContext();

navigator.getUserMedia({ audio: true }, function(stream) {
  // the important thing is to save a reference to the MediaStreamAudioSourceNode
  // thus, *window*.source or any other object reference will do
  window.source = context.createMediaStreamSource(stream);
  source.connect(context.destination);
}, alert);
4b9b3361

Ответ 1

Это ошибка в Firefox, ее можно найти здесь:

https://bugzilla.mozilla.org/show_bug.cgi?id=934512

Существует также обходное решение:

context = new AudioContext();

navigator.getUserMedia({ audio: true }, function(stream) {
  // the important thing is to save a reference to the MediaStreamAudioSourceNode
  // thus, *window*.source or any other object reference will do
  window.source = context.createMediaStreamSource(stream);
  source.connect(context.destination);
}, alert);

источник