Search code examples
javascripthtmlgoogle-chromegetusermedia

"getUserMedia" not working in Chrome Version 36.0.1985.125 m


I was following the tutorial for audio GUM with this HTML5Rocks post. Here is the code:

function gotStream(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 );
}

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
navigator.getUserMedia({audio:true}, gotStream,function(e){console.log(e);});

I tried running this in Chrome, but absolutely nothing happened. No errors, or anything. The "asking for permission" dialog did not show up either.

I'm using Chrome Version 36.0.1985.125 m.


Solution

  • The problem is that you are trying to access your ../*.html file directly. Chrome won't correctly for a number of features due to the Same Origin Policy. There are two solutions.

    1. Set up a simple http server. You can do this by enabling apache to serve your local files for you.

    2. Disable same origin policy for chrome.

    A quick google for both will turn up several full detailed examples on how to do either. I would suggest option 1 because this will emulate how your webpage will behave when it is live.