open source guy
open source guy

Reputation: 2787

How request microphone access in html5

i have code like this

function initAudio() {
    if (!navigator.webkitGetUserMedia)
        return(alert("Error: getUserMedia not supported!"));

    navigator.webkitGetUserMedia({audio:true}, gotStream, function(e) {
            alert('Error getting audio');
            console.log(e);
        });
}

window.addEventListener('load', initAudio );

my output in console is this

NavigatorUserMediaError {code: 1, PERMISSION_DENIED: 1} 

why permission deny for me? I try to make audio recorder from source code of this page http://webaudiodemos.appspot.com/AudioRecorder/index.html

Upvotes: 2

Views: 5089

Answers (1)

Dominic Green
Dominic Green

Reputation: 10258

If your running your code from a file saved on your machine not through a web server, chrome sometimes has issues with allowing access due to its secuirty policy.

Two options to try are

  1. Putting it on a web server
  2. Opening chrome through terminal using the command below if you are on mac

    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files

Upvotes: 4

Related Questions