简体   繁体   中英

Get mic/webcam record stream using javascript/html5 only

I making a web application that need to record stream from the pc/mobile mic/camera using java script and html5(no flash). how i can do it?

There are two methods, getusermedia and the legacy method using an input, which is what ios6 allows:

Old way:

<input type="file" accept="video/*;capture=camcorder">
<input type="file" accept="audio/*;capture=microphone">

Current way:

window.URL = window.URL || window.webkitURL;
navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia ||
                          navigator.mozGetUserMedia || navigator.msGetUserMedia;

var video = document.querySelector('video');

if (navigator.getUserMedia) {
  navigator.getUserMedia({audio: true, video: true}, function(stream) {
    video.src = window.URL.createObjectURL(stream);
  }, onFailSoHard);
} else {
  video.src = 'somevideo.webm'; // fallback.
}

These samples were copied from here . HTML5Rocks has many working samples as well.

navigator.getUserMedia ( constraints, successCallback, errorCallback );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM