<span style="white-space:pre"></span><audio controls autoplay></audio>
<input type="button" value="开始录音" onclick="startRecording()"/>
<input type="button" value="获取录音" onclick="obtainRecord()"/>
<input type="button" value="停止录音" onclick="stopRecord()"/>
<input type="button" value="播放录音" onclick="playRecord()"/>
<video id="video1" width="320px" height="240px" controls autoplay ></video>
<video id="video2" width="320px" height="240px" controls autoplay ></video>
<canvas id="canvas1" width="320" height="240"></canvas>
<input type="button" value="拍摄" onclick="scamera()"/>
<input type="button" value="播放视频" onclick="playVideo()"/>
(function (window) {
//兼容
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
var HZRecorder = function (stream, config) {
config = config || {};
config.sampleBits = config.sampleBits || 8; //采样数位 8, 16
config.sampleRate = config.sampleRate || (44100 / 6); //采样率(1/6 44100)
//创建一个音频环境对象
audioContext = window.AudioContext || window.webkitAudioContext;
var context = new audioContext();
//将声音输入这个对像
var audioInput = context.createMediaStreamSource(stream);
//设置音量节点
var volume = context.createGain();
audioInput.connect(volume);
//创建缓存,用来缓存声音
var bufferSize = 4096;
// 创建声音的缓存节点,createScriptProcessor方法的
// 第二个和第三个参数指的是输入和输出都是双声道。
var recorder = context.createScriptProcessor(bufferSize, 2, 2);
var audioData = {
size: 0 //录音文件长度
, buffer: [] //录音缓存
, inputSampleRate: context.sampleR