MediaStreamRecorder是用于记录getUserMedia()流(仍在实现)的WebRTC API。它允许网络应用程序从现场音频/视频会话创建文件。
function onVideoFail(e) {
console.log('webcam fail!',e);
};
function hasGetUserMedia() {
// Note: Opera is unprefixed.
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
if (hasGetUserMedia()) {
// Good to go!
} else {
alert('getUserMedia() is not supported in your browser');
}
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
var video = document.querySelector('video');
var streamRecorder;
var webcamstream;
if (navigator.getUserMedia) {
navigator.getUserMedia({audio: true,video: true},function(stream) {
video.src = window.URL.createObjectURL(stream);
webcamstream = stream;
// streamrecorder = webcamstream.record();
},onVideoFail);
} else {
alert ('Failed');
}
function startRecording() {
streamRecorder = webcamstream.record();
setTimeout(stopRecording,10000);
}
function stopRecording() {
streamRecorder.getRecordedData(postVideoToServer);
}
function postVideoToServer(videoblob) {
var data = {};
data.video = videoblob;
data.Metadata = 'test Metadata';
data.action = "upload_video";
jQuery.post("http://www.foundthru.co.uk/uploadvideo.PHP",data,onUploadSuccess);
}
function onUploadSuccess() {
alert ('video uploaded');
}
RECORD