1

我为视频录制和上传编写了 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> 
4

1 回答 1

1

根据 getMediaStream API 的规范草案,没有名为 record() 的方法W3C 媒体捕获草案

您可以尝试通过在画布上绘制每一帧并使用新的文件系统 API 将其保存到临时图像文件来实现记录。也许稍后我可以为您提供一个示例。它已经使用 Webkit-Engine 完成了。看这里

于 2013-08-29T16:36:32.243 回答