我为视频录制和上传编写了 html 5 代码。当点击开始按钮时,它会产生一个 javascript 错误。“TypeError:webcamstream.record 不是函数 streamRecorder = webcamstream.record();” “TypeError:streamRecorder 未定义 streamRecorder.getRecordedData(postVideoToServer);”
它仅适用于 mozilla 浏览器。请帮助我...代码是
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
var streamRecorder;
var webcamstream;
function enter()
{
if (navigator.mozGetUserMedia) {
navigator.myGetMedia=navigator.mozGetUserMedia;
navigator.myGetMedia({video: true}, connect, error);
}
else {
alert("N");
}
function connect(stream)
{
var video = document.getElementById("my_video");
video.src = window.URL ? window.URL.createObjectURL(stream) : stream;
webcamstream = stream;
video.play();
}
function error(e) { console.log(e); }
}
function startRecording()
{
alert('STARTING');
streamRecorder = webcamstream.record();
setTimeout(stopRecording, 10000);
}
function stopRecording()
{
alert('STOP');
streamRecorder.getRecordedData(postVideoToServer);
}
function postVideoToServer(videoblob) {
alert ('start video uploaded');
var data = {};
data.video = videoblob;
data.metadata = 'test metadata';
data.action = "upload_video";
jQuery.post("http://www.kongraju.in/uploadvideo.php", data, onUploadSuccess);
}
function onUploadSuccess() {
alert ('video uploaded');
}
</script>
<title>Untitled Document</title>
</head>
<body>
<canvas width="640" height="480" id="c"></canvas>
<input type="button" value="START CAMERA" onClick="enter()"/>
<input type="button" value="START RECORD" onClick="startRecording()"/>
<input type="button" value="STOP RECORD" onClick="stopRecording()"/>
<video id="my_video" width="640" height="480"/>
</body>
</html>