Commit fc3a5852332096711690eead6e63022b36031b33
1 parent
d8870822
fix bug
Showing
9 changed files
with
428 additions
and
15 deletions
kkb@192.168.30.25
0 → 100644
No preview for this file type
src/gxb-ide/CodingEditer.js
| 1 | 1 | ;(function(window){ |
| 2 | - var isReplayPage = false; | |
| 3 | 2 | |
| 4 | 3 | var CodingEditer = { |
| 5 | 4 | records: [], // 存储录入的操作 |
| ... | ... | @@ -271,7 +270,9 @@ |
| 271 | 270 | console.log(status + '##########################') |
| 272 | 271 | if (status == 0 || status == 1) { |
| 273 | 272 | for (var i = 0; i < treeLinkEditor.length; i++) { |
| 274 | - treeLinkEditor[i].CodeMirrorRecord.setOption('readOnly', status); | |
| 273 | + if(!Dir.isReplayPage){ | |
| 274 | + treeLinkEditor[i].CodeMirrorRecord.setOption('readOnly', status); | |
| 275 | + } | |
| 275 | 276 | treeLinkEditor[i].CodeMirrorReplay.setOption('readOnly', status); |
| 276 | 277 | } |
| 277 | 278 | }else{ |
| ... | ... | @@ -289,7 +290,7 @@ |
| 289 | 290 | // 生成 CodeMirror |
| 290 | 291 | for (var i = 0; i < treeLinkEditor.length; i++) { |
| 291 | 292 | // 判断是否是播放页面,如果是则不显示录制区相关dom |
| 292 | - if(!isReplayPage){ | |
| 293 | + if(!Dir.isReplayPage){ | |
| 293 | 294 | treeLinkEditor[i].CodeMirrorRecord = CodeMirror.fromTextArea($('#' + treeLinkEditor[i].record)[0], { |
| 294 | 295 | value: '', |
| 295 | 296 | mode: modeName, | ... | ... |
src/gxb-ide/Dir.js
| ... | ... | @@ -50,6 +50,7 @@ |
| 50 | 50 | treeLinkEditor: [], // 缓存整个目录树结构和代码编辑器的关系 |
| 51 | 51 | mainPath: null, // 运行编译时候需要知道当前是哪个文件 |
| 52 | 52 | treeObj: null, |
| 53 | + isReplayPage: false, | |
| 53 | 54 | init: function(){ |
| 54 | 55 | console.log('======================='); |
| 55 | 56 | }, |
| ... | ... | @@ -94,6 +95,7 @@ |
| 94 | 95 | getCodeData(playUrl, el) |
| 95 | 96 | } |
| 96 | 97 | |
| 98 | + | |
| 97 | 99 | // if (role == 0) { |
| 98 | 100 | // playUrl = gxb_api + "/programming/codeReplay/" + _codeReplayId + "/api"; |
| 99 | 101 | // } else if (role == 1) { |
| ... | ... | @@ -219,7 +221,7 @@ |
| 219 | 221 | var _arr = []; |
| 220 | 222 | var treeLinkEditor = Dir.treeLinkEditor; |
| 221 | 223 | console.log(treeLinkEditor); |
| 222 | - if(!isReplayPage){ | |
| 224 | + if(!Dir.isReplayPage){ | |
| 223 | 225 | // 判断是否是需要返回单文件结果 |
| 224 | 226 | if(name){ |
| 225 | 227 | for (var i = 0; i < treeLinkEditor.length; i++) { |
| ... | ... | @@ -487,7 +489,7 @@ |
| 487 | 489 | "replay": _name + 'Replay' |
| 488 | 490 | }); |
| 489 | 491 | // 判断是否是播放页面,如果是则不显示录制区相关dom |
| 490 | - if(!isReplayPage){ | |
| 492 | + if(!Dir.isReplayPage){ | |
| 491 | 493 | recordTemplate += '<div class="coding" id="'+ _name +'RecordWrap"><textarea id="'+ _name + 'Record" title="'+ _name +'" style="display: none;">'+defaultValue+'</textarea></div>' |
| 492 | 494 | } |
| 493 | 495 | |
| ... | ... | @@ -495,7 +497,7 @@ |
| 495 | 497 | } |
| 496 | 498 | } |
| 497 | 499 | // 判断是否是播放页面,如果是则不显示录制区相关dom |
| 498 | - if(!isReplayPage){ | |
| 500 | + if(!Dir.isReplayPage){ | |
| 499 | 501 | $('#recordzone').append(recordTemplate); |
| 500 | 502 | } |
| 501 | 503 | $('#replayzone').append(replayTemplate); |
| ... | ... | @@ -587,16 +589,19 @@ |
| 587 | 589 | dataType: "json", |
| 588 | 590 | contentType: "application/json", |
| 589 | 591 | success: function(res) { |
| 590 | - console.log('0000--------------------') | |
| 591 | 592 | console.log(res) |
| 592 | - setTitle(res.languageid); | |
| 593 | + $('.button.edit').hide(); | |
| 593 | 594 | |
| 595 | + setTitle(res.languageid); | |
| 596 | + Dir.languageid = res.languageid; | |
| 594 | 597 | var coderecords = res.codeRecordList || res.studentRecordList; |
| 595 | 598 | var audioUrl = res.audioUrl; |
| 596 | 599 | |
| 597 | 600 | var treeArr = res.programmingFileList; |
| 598 | 601 | Dir.treeData = programFileListToTreeJson(treeArr); |
| 599 | 602 | Dir.treeObj = $.fn.zTree.init($(el), setting, Dir.treeData); |
| 603 | + Dir.treeObj.setting.edit.showRenameBtn = false; | |
| 604 | + Dir.treeObj.setting.edit.enable = false; | |
| 600 | 605 | |
| 601 | 606 | addTextareaPage(Dir.treeData); |
| 602 | 607 | CodingEditer.initCodeMirror(treeLinkEditor); | ... | ... |
src/gxb-ide/Iterm.js
| ... | ... | @@ -31,7 +31,8 @@ |
| 31 | 31 | var _this = this; |
| 32 | 32 | var el = document.querySelector('#CompileBtn'); |
| 33 | 33 | var userId = _this.options.userId; |
| 34 | - var languageId = _this.options.languageId; | |
| 34 | + // var languageId = _this.options.languageId; | |
| 35 | + var languageId = _this.options.languageId || Dir.languageid; | |
| 35 | 36 | var role = getQuery('role'); |
| 36 | 37 | // 判断是否录制走不同的逻辑 |
| 37 | 38 | if (!CodingEditer.isRcording) { |
| ... | ... | @@ -52,9 +53,8 @@ |
| 52 | 53 | CodingEditer.addRecord(treeNode, check_tree_time); |
| 53 | 54 | |
| 54 | 55 | _this.compileStatus = false; |
| 55 | - console.log('******************************' + this.compileStatus) | |
| 56 | 56 | } |
| 57 | - | |
| 57 | + console.log('******************************' + languageId) | |
| 58 | 58 | compileMode(el, userId, languageId) |
| 59 | 59 | $('.contrl-shodow').show(); |
| 60 | 60 | } | ... | ... |
src/index.html
src/js/gbreplayer.js
| ... | ... | @@ -1429,9 +1429,12 @@ $(function(){ |
| 1429 | 1429 | var runStatus = $("#comprun").data('run'); |
| 1430 | 1430 | if (runStatus == 1) { |
| 1431 | 1431 | Hourglass.pauseTimer(); // 暂停计时器 |
| 1432 | - recorder.pause(); // 音频暂停 | |
| 1432 | + if (_role == 0) { | |
| 1433 | + recorder.pause(); // 音频暂停 | |
| 1434 | + } | |
| 1433 | 1435 | } |
| 1434 | 1436 | $("#comprun").data('run', 0); |
| 1437 | + $('.pause-shodow').show(); | |
| 1435 | 1438 | $('.compile-loading').show(); |
| 1436 | 1439 | // 暂停录制 |
| 1437 | 1440 | var pauseState = $('#pause').data('pause'); | ... | ... |
src/js/player.js
| ... | ... | @@ -18,13 +18,13 @@ $(function(){ |
| 18 | 18 | |
| 19 | 19 | // 编译控制台 |
| 20 | 20 | var iterm = new Iterm({ |
| 21 | - userId: _userId, | |
| 22 | - languageId: _languageid | |
| 21 | + userId: _userId | |
| 23 | 22 | }); |
| 24 | 23 | |
| 25 | 24 | console.log(_role) |
| 26 | 25 | |
| 27 | 26 | CodingEditer.isRecordPage = 0; |
| 27 | + Dir.isReplayPage = true; | |
| 28 | 28 | |
| 29 | 29 | $('.play-code').on('click', function(){ |
| 30 | 30 | console.log('=================') | ... | ... |
src/js/recorder1/Myna.js
0 → 100644
| 1 | +(function(window) { | |
| 2 | + //兼容 | |
| 3 | + window.URL = window.URL || window.webkitURL; | |
| 4 | + navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; | |
| 5 | + | |
| 6 | + var HZRecorder = function(stream, config) { | |
| 7 | + config = config || {}; | |
| 8 | + config.sampleBits = config.sampleBits || 16; //采样数位 8, 16 | |
| 9 | + config.sampleRate = config.sampleRate || 11025; //采样率(1/6 44100) | |
| 10 | + | |
| 11 | + var context = new(window.webkitAudioContext || window.AudioContext)(); | |
| 12 | + var audioInput = context.createMediaStreamSource(stream); | |
| 13 | + var createScript = context.createScriptProcessor || context.createJavaScriptNode; | |
| 14 | + var recorder = createScript.apply(context, [4096, 1, 1]); | |
| 15 | + | |
| 16 | + var audioData = { | |
| 17 | + size: 0, //录音文件长度 | |
| 18 | + buffer: [], //录音缓存 | |
| 19 | + inputSampleRate: context.sampleRate, //输入采样率 | |
| 20 | + inputSampleBits: 16, //输入采样数位 8, 16 | |
| 21 | + outputSampleRate: config.sampleRate, //输出采样率 | |
| 22 | + oututSampleBits: config.sampleBits, //输出采样数位 8, 16 | |
| 23 | + input: function(data) { | |
| 24 | + this.buffer.push(new Float32Array(data)); | |
| 25 | + this.size += data.length; | |
| 26 | + }, | |
| 27 | + compress: function() { //合并压缩 | |
| 28 | + //合并 | |
| 29 | + var data = new Float32Array(this.size); | |
| 30 | + var offset = 0; | |
| 31 | + for (var i = 0; i < this.buffer.length; i++) { | |
| 32 | + data.set(this.buffer[i], offset); | |
| 33 | + offset += this.buffer[i].length; | |
| 34 | + } | |
| 35 | + //压缩 | |
| 36 | + var compression = parseInt(this.inputSampleRate / this.outputSampleRate); | |
| 37 | + var length = data.length / compression; | |
| 38 | + var result = new Float32Array(length); | |
| 39 | + var index = 0, | |
| 40 | + j = 0; | |
| 41 | + while (index < length) { | |
| 42 | + result[index] = data[j]; | |
| 43 | + j += compression; | |
| 44 | + index++; | |
| 45 | + } | |
| 46 | + return result; | |
| 47 | + }, | |
| 48 | + encodeWAV: function() { | |
| 49 | + var sampleRate = Math.min(this.inputSampleRate, this.outputSampleRate); | |
| 50 | + var sampleBits = Math.min(this.inputSampleBits, this.oututSampleBits); | |
| 51 | + var bytes = this.compress(); | |
| 52 | + var dataLength = bytes.length * (sampleBits / 8); | |
| 53 | + var buffer = new ArrayBuffer(44 + dataLength); | |
| 54 | + var data = new DataView(buffer); | |
| 55 | + | |
| 56 | + var channelCount = 1; //单声道 | |
| 57 | + var offset = 0; | |
| 58 | + | |
| 59 | + var writeString = function(str) { | |
| 60 | + for (var i = 0; i < str.length; i++) { | |
| 61 | + data.setUint8(offset + i, str.charCodeAt(i)); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + // 资源交换文件标识符 | |
| 66 | + writeString('RIFF'); | |
| 67 | + offset += 4; | |
| 68 | + // 下个地址开始到文件尾总字节数,即文件大小-8 | |
| 69 | + data.setUint32(offset, 36 + dataLength, true); | |
| 70 | + offset += 4; | |
| 71 | + // WAV文件标志 | |
| 72 | + writeString('WAVE'); | |
| 73 | + offset += 4; | |
| 74 | + // 波形格式标志 | |
| 75 | + writeString('fmt '); | |
| 76 | + offset += 4; | |
| 77 | + // 过滤字节,一般为 0x10 = 16 | |
| 78 | + data.setUint32(offset, 16, true); | |
| 79 | + offset += 4; | |
| 80 | + // 格式类别 (PCM形式采样数据) | |
| 81 | + data.setUint16(offset, 1, true); | |
| 82 | + offset += 2; | |
| 83 | + // 通道数 | |
| 84 | + data.setUint16(offset, channelCount, true); | |
| 85 | + offset += 2; | |
| 86 | + // 采样率,每秒样本数,表示每个通道的播放速度 | |
| 87 | + data.setUint32(offset, sampleRate, true); | |
| 88 | + offset += 4; | |
| 89 | + // 波形数据传输率 (每秒平均字节数) 单声道×每秒数据位数×每样本数据位/8 | |
| 90 | + data.setUint32(offset, channelCount * sampleRate * (sampleBits / 8), true); | |
| 91 | + offset += 4; | |
| 92 | + // 快数据调整数 采样一次占用字节数 单声道×每样本的数据位数/8 | |
| 93 | + data.setUint16(offset, channelCount * (sampleBits / 8), true); | |
| 94 | + offset += 2; | |
| 95 | + // 每样本数据位数 | |
| 96 | + data.setUint16(offset, sampleBits, true); | |
| 97 | + offset += 2; | |
| 98 | + // 数据标识符 | |
| 99 | + writeString('data'); | |
| 100 | + offset += 4; | |
| 101 | + // 采样数据总数,即数据总大小-44 | |
| 102 | + data.setUint32(offset, dataLength, true); | |
| 103 | + offset += 4; | |
| 104 | + // 写入采样数据 | |
| 105 | + if (sampleBits === 8) { | |
| 106 | + for (var i = 0; i < bytes.length; i++, offset++) { | |
| 107 | + var s = Math.max(-1, Math.min(1, bytes[i])); | |
| 108 | + var val = s < 0 ? s * 0x8000 : s * 0x7FFF; | |
| 109 | + val = parseInt(255 / (65535 / (val + 32768))); | |
| 110 | + data.setInt8(offset, val, true); | |
| 111 | + } | |
| 112 | + } else { | |
| 113 | + for (var i = 0; i < bytes.length; i++, offset += 2) { | |
| 114 | + var s = Math.max(-1, Math.min(1, bytes[i])); | |
| 115 | + data.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + return new Blob([data], { type: 'audio/wav' }); | |
| 120 | + } | |
| 121 | + }; | |
| 122 | + | |
| 123 | + //开始录音 | |
| 124 | + this.start = function() { | |
| 125 | + audioInput.connect(recorder); | |
| 126 | + recorder.connect(context.destination); | |
| 127 | + } | |
| 128 | + | |
| 129 | + // 暂停继续 | |
| 130 | + this.pause = function() { | |
| 131 | + console.log(context.state); | |
| 132 | + if (context.state === 'running') { | |
| 133 | + context.suspend().then(function() { | |
| 134 | + }); | |
| 135 | + } else if (context.state === 'suspended') { | |
| 136 | + context.resume().then(function() { | |
| 137 | + }); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + //停止 | |
| 142 | + this.stop = function() { | |
| 143 | + context.close().then(function(){ | |
| 144 | + recorder.disconnect(); | |
| 145 | + }); | |
| 146 | + | |
| 147 | + console.log(this.getBlob); | |
| 148 | + } | |
| 149 | + | |
| 150 | + //获取音频文件 | |
| 151 | + this.getBlob = function() { | |
| 152 | + this.stop(); | |
| 153 | + return audioData.encodeWAV(); | |
| 154 | + } | |
| 155 | + | |
| 156 | + // 获取音频文件 | |
| 157 | + this.getBlobData = function(){ | |
| 158 | + console.log(audioData.encodeWAV()); | |
| 159 | + // return audioData.encodeWAV(); | |
| 160 | + $('#audio').attr('src', window.URL.createObjectURL(this.getBlob())); | |
| 161 | + } | |
| 162 | + | |
| 163 | + //回放 | |
| 164 | + this.play = function(audio) { | |
| 165 | + console.log(window.URL.createObjectURL(this.getBlob())) | |
| 166 | + audio.src = window.URL.createObjectURL(this.getBlob()); | |
| 167 | + } | |
| 168 | + | |
| 169 | + this.download = function(saveAudio) { | |
| 170 | + var url = window.URL.createObjectURL(this.getBlob()); | |
| 171 | + console.log(url); | |
| 172 | + saveAudio.href = url; | |
| 173 | + saveAudio.download = 'output.wav'; | |
| 174 | + } | |
| 175 | + | |
| 176 | + //上传 | |
| 177 | + this.upload = function(url, callback) { | |
| 178 | + var file = audioData.encodeWAV(); | |
| 179 | + var $this = $(this); | |
| 180 | + console.log(file); | |
| 181 | + var megabyte = 1024 * 1024; | |
| 182 | + var defaultChnkSize = 5 * megabyte; | |
| 183 | + | |
| 184 | + var date = new Date(); | |
| 185 | + var year = date.getFullYear(); | |
| 186 | + var month = date.getMonth() + 1; | |
| 187 | + var today = date.getDate(); | |
| 188 | + var path = "uploads/programming_audio/link/" + String(year).substr(2) + "/" + (String(month).length == 1?"0" + month:month)+ "/" + today + "/"; | |
| 189 | + | |
| 190 | + var parameterConfig = { | |
| 191 | + filename: 'asdfas', | |
| 192 | + filesize: file.size, | |
| 193 | + filetype: file.type, | |
| 194 | + isPart: false, | |
| 195 | + uploadId: "", | |
| 196 | + isCompleted: false, | |
| 197 | + prefix: path, // "uploads/programming_audio/link" | |
| 198 | + bucket: "gxb-file", ///“gxb-file” | |
| 199 | + defaultChunkSize: defaultChnkSize || 0, | |
| 200 | + isVideoConvert: false, | |
| 201 | + isClassCover: false | |
| 202 | + }; | |
| 203 | + var parameter = JSON.stringify(parameterConfig); | |
| 204 | + console.log(parameter); | |
| 205 | + gxb._.ajax(gxb_api + '/s3', { | |
| 206 | + type: 'POST', | |
| 207 | + contentType: "application/json", | |
| 208 | + // async:false, | |
| 209 | + data: parameter, | |
| 210 | + crossDomain: true, | |
| 211 | + success: function(res) { | |
| 212 | + console.log(res); | |
| 213 | + successUrl = res; | |
| 214 | + var queue = []; | |
| 215 | + if (parameterConfig.isPart === true) { | |
| 216 | + var partsArr = []; | |
| 217 | + var parts = utils.toJsonObj(res)[0]; | |
| 218 | + parameterConfig.uploadId = parts.upload_id; | |
| 219 | + var obj = { | |
| 220 | + md5: parameterConfig.md5, //文件的md5 | |
| 221 | + loadedNum: "0", //目前上传大小 | |
| 222 | + total: parts.multi_list[parts.multi_list.length - 1].part_end, //总大小 | |
| 223 | + partsLen: parts.multi_list.length, //分片个数 | |
| 224 | + successNum: parts.successNum, //成功的个数 | |
| 225 | + succesUrl: successUrl, | |
| 226 | + file: file, | |
| 227 | + max_size: 5, | |
| 228 | + coment_size: 0, | |
| 229 | + errorNum: 0 | |
| 230 | + } | |
| 231 | + console.log(obj); | |
| 232 | + uploadArr.push(obj) | |
| 233 | + for (var partIndex = 0; partIndex < parts.total_num; partIndex++) { | |
| 234 | + var partItem = parts.multi_list[partIndex]; | |
| 235 | + console.log(partItem.part_url) | |
| 236 | + console.log(partItem.part_begin + ' -> ' + partItem.part_end); | |
| 237 | + var loadedNum = 0; | |
| 238 | + if (partItem && partItem.isSuccess != 1) { | |
| 239 | + queue.push(partItem); | |
| 240 | + loadedNum = 0; | |
| 241 | + } else { | |
| 242 | + loadedNum = partItem.upload_len; | |
| 243 | + } | |
| 244 | + var partOne = { | |
| 245 | + loaded: loadedNum, | |
| 246 | + part_idx: partItem.part_idx | |
| 247 | + } | |
| 248 | + partsArr.push(partOne); | |
| 249 | + } | |
| 250 | + partsArr.reverse(); | |
| 251 | + queue.reverse(); | |
| 252 | + } else { | |
| 253 | + uploadFileHandler(false, $this, file, file, res, successUrl, parameterConfig) | |
| 254 | + } | |
| 255 | + } | |
| 256 | + }); | |
| 257 | + } | |
| 258 | + | |
| 259 | + //音频采集 | |
| 260 | + recorder.onaudioprocess = function(e) { | |
| 261 | + audioData.input(e.inputBuffer.getChannelData(0)); | |
| 262 | + //record(e.inputBuffer.getChannelData(0)); | |
| 263 | + } | |
| 264 | + | |
| 265 | + }; | |
| 266 | + | |
| 267 | + var uploadFileHandler = function(isMultiPart, $this, file, data, url, successUrl, parameter, partItem, queue, obj, partsArr) { | |
| 268 | + | |
| 269 | + var headers = { 'x-amz-acl': 'public-read' } | |
| 270 | + if (isMultiPart == true) { | |
| 271 | + headers = { 'Access-Control-Allow-Origin': "https://" + window.location.host } | |
| 272 | + } else { | |
| 273 | + headers = { 'x-amz-acl': 'public-read' } | |
| 274 | + } | |
| 275 | + console.log(url); | |
| 276 | + | |
| 277 | + url = 'https' + url.split('https')[1]; | |
| 278 | + $.ajax({ | |
| 279 | + url: url, | |
| 280 | + type: 'PUT', | |
| 281 | + data: data, | |
| 282 | + headers: headers, | |
| 283 | + contentType: file.type, | |
| 284 | + processData: false, | |
| 285 | + crossDomain: true, | |
| 286 | + beforeSend: function(){ | |
| 287 | + // $('#uploading').css('dispaly', 'block') | |
| 288 | + }, | |
| 289 | + success: function(data) { | |
| 290 | + console.log(data) | |
| 291 | + $('#uploading').css('display', 'none') | |
| 292 | + var audioUrl = getCDNFile(url) | |
| 293 | + console.log(audioUrl) | |
| 294 | + $(".audio-url").val(audioUrl) | |
| 295 | + | |
| 296 | + $('#savecorde').trigger('click'); | |
| 297 | + | |
| 298 | + }, | |
| 299 | + error: function(res){ | |
| 300 | + $('.upload-tip').hide(); | |
| 301 | + alert('音频保存失败...') | |
| 302 | + console.log(res) | |
| 303 | + } | |
| 304 | + }); | |
| 305 | + } | |
| 306 | + //抛出异常 | |
| 307 | + HZRecorder.throwError = function(message) { | |
| 308 | + alert(message); | |
| 309 | + throw new function() { this.toString = function() { | |
| 310 | + return message; } } | |
| 311 | + } | |
| 312 | + //是否支持录音 | |
| 313 | + HZRecorder.canRecording = (navigator.getUserMedia != null); | |
| 314 | + //获取录音机 | |
| 315 | + HZRecorder.get = function(callback, config) { | |
| 316 | + if (callback) { | |
| 317 | + if (navigator.getUserMedia) { | |
| 318 | + navigator.getUserMedia({ audio: true } //只启用音频 | |
| 319 | + , | |
| 320 | + function(stream) { | |
| 321 | + var rec = new HZRecorder(stream, config); | |
| 322 | + callback(rec); | |
| 323 | + }, | |
| 324 | + function(error) { | |
| 325 | + $('.error').css('display', 'block'); | |
| 326 | + $('.error-btn').click(function(){ | |
| 327 | + $('.error').hide(); | |
| 328 | + }) | |
| 329 | + switch (error.code || error.name) { | |
| 330 | + case 'PERMISSION_DENIED': | |
| 331 | + case 'PermissionDeniedError': | |
| 332 | + HZRecorder.throwError('用户拒绝提供信息。'); | |
| 333 | + break; | |
| 334 | + case 'NOT_SUPPORTED_ERROR': | |
| 335 | + case 'NotSupportedError': | |
| 336 | + HZRecorder.throwError('浏览器不支持硬件设备。'); | |
| 337 | + break; | |
| 338 | + case 'MANDATORY_UNSATISFIED_ERROR': | |
| 339 | + case 'MandatoryUnsatisfiedError': | |
| 340 | + HZRecorder.throwError('无法发现指定的硬件设备。'); | |
| 341 | + break; | |
| 342 | + default: | |
| 343 | + HZRecorder.throwError('无法打开麦克风。异常信息:' + (error.code || error.name)); | |
| 344 | + break; | |
| 345 | + } | |
| 346 | + }); | |
| 347 | + } else { | |
| 348 | + HZRecorder.throwErr('当前浏览器不支持录音功能。'); | |
| 349 | + return; | |
| 350 | + } | |
| 351 | + } | |
| 352 | + } | |
| 353 | + | |
| 354 | + window.HZRecorder = HZRecorder; | |
| 355 | + | |
| 356 | +})(window); | ... | ... |
src/js/recorder1/recorder.js
0 → 100644
| 1 | + | |
| 2 | +$(function(){ | |
| 3 | + | |
| 4 | + var recorder; | |
| 5 | + | |
| 6 | + var audio = document.querySelector('audio'); | |
| 7 | + // var audio = document.getElementById('audio'); | |
| 8 | + | |
| 9 | + function startRecording() { | |
| 10 | + | |
| 11 | + } | |
| 12 | + | |
| 13 | + function stopRecording() { | |
| 14 | + recorder.stop(); | |
| 15 | + } | |
| 16 | + | |
| 17 | + function playRecording() { | |
| 18 | + | |
| 19 | + recorder.play(audio); | |
| 20 | + } | |
| 21 | + | |
| 22 | + | |
| 23 | + // $("#startRec").trigger('click'); | |
| 24 | + | |
| 25 | + function uploadAudio() { | |
| 26 | + recorder.upload("", function (state, e) { | |
| 27 | + switch (state) { | |
| 28 | + case 'uploading': | |
| 29 | + //var percentComplete = Math.round(e.loaded * 100 / e.total) + '%'; | |
| 30 | + break; | |
| 31 | + case 'ok': | |
| 32 | + console.log(e.target.responseText); | |
| 33 | + alert("上传成功"); | |
| 34 | + break; | |
| 35 | + case 'error': | |
| 36 | + alert("上传失败"); | |
| 37 | + break; | |
| 38 | + case 'cancel': | |
| 39 | + alert("上传被取消"); | |
| 40 | + break; | |
| 41 | + } | |
| 42 | + }); | |
| 43 | + } | |
| 44 | + | |
| 45 | + | |
| 46 | +}); | |
| 47 | + | |
| 48 | + | ... | ... |