(function(){ navigator.getUserMedia=navigator.getUserMedia||navigator.mozGetUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia; if (navigator.getUserMedia) { // console.log('navigator.getUserMedia'); navigator.getUserMedia({ audio:true },onSuccess,onError); } else { throw new Error("sorry ,getUserMedia() is navigator supported in your browser"); } }()) function onSuccess(stream){ // alert("get the navigator getUserMedia"); var audio=document.createElement("audio"); audio.autoplay=true; // console.log(stream.getAudioTracks()); document.body.appendChild(audio); if (window.URL) { // Chrome浏览器: URL.createObjectURL() 把 MediaStream 转为 blob URL audio.src= window.URL.createObjectURL(stream); console.log("ddd"); } else { // Firefox和Opera: 可以直接把视频源设置为stream audio.src = stream; } // 播放 audio.play(); // start.addEventListener('click',function(){beginbutton(video);},false); // pause.addEventListener('click',function(){stopbutton(video);},false); } function onError(){ throw new Error("there is problem"); }