Skip to content

Commit

Permalink
调整demo代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Jan 15, 2020
1 parent fbefe77 commit 72a46ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
37 changes: 35 additions & 2 deletions app-support-sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@
<button class="mainBtn" onclick="recstart()">录制</button>
<button class="mainBtn" onclick="recstop()" style="margin-right:80px;">停止</button>

<button onclick="recstopX()">停止(仅清理)</button>
<button onclick="recstopX()" style="margin-right:40px;">停止(仅清理)</button>

<span style="display: inline-block;">
<button onclick="recstartAndAutoStop()">录制+定时停止</button><input value="0" class="autoStopTime" style="width:60px;">ms
</span>
</div>
<div class="pd recpower">
<div style="height:40px;width:300px;background:#999;position:relative;">
Expand Down Expand Up @@ -370,6 +374,8 @@
RecordApp.alwaysAppUseJSPrev=alwaysAppUseJS;
};
RecordApp.AlwaysAppUseJS=alwaysAppUseJS;

cancelAutoStop();
};
function recreq(){
baseSet();
Expand Down Expand Up @@ -423,7 +429,32 @@
//弹框End


var curSet;
var curSet,autoStopTimer;
function recstartAndAutoStop(){
var time=+$(".autoStopTime").val()||0;
if(time<100){
reclog("定时不能小于100ms",1);
return;
};
recstart(function(msg){
if(msg){
msg&&reclog(msg,1);
return;
};
reclog("定时"+time+"ms后自动停止录音");
autoStopTimer=setTimeout(function(){
reclog("定时时间到,开始自动调用停止...");
recstop();
},time);
});
};
var cancelAutoStop=function(){
if(autoStopTimer){
reclog("已取消定时停止",1);
clearTimeout(autoStopTimer);
autoStopTimer=0;
};
};
function recstart(call){
call||(call=function(msg){
msg&&reclog(msg,1);
Expand Down Expand Up @@ -499,6 +530,7 @@
});
};
function recstopX(){
cancelAutoStop();
RecordApp.Stop(
null //success传null就只会清理资源,不会进行转码
,function(msg){
Expand All @@ -515,6 +547,7 @@
});
};
function recstopFn(call,isClick,endCall,rec){
cancelAutoStop();
call||(call=function(msg){
msg&&reclog(msg,1);
});
Expand Down
14 changes: 12 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,17 @@

rec.open(function(){
dialogCancel();
reclog("<span style='color:#0b1'>已打开:"+type+" "+sample+"hz "+bit+"kbps</span>");
var typeSize=",<span style='border:1px solid #bbb;background:#f5f5f5;'>";
if(type=="wav"){
typeSize+="1秒的wav文件大小(字节)估算公式:采样率 × 位数 ÷ 8,当前:"+sample+"*"+bit+"/8≈"+(sample*bit/8)+"b/s";
}else if(type=="mp3"){
typeSize+="1秒的mp3文件大小(字节)估算公式:比特率 × 1000 ÷ 8,当前:"+bit+"*1000/8≈"+(bit*1000/8)+"b/s";
}else{
typeSize="";
};
typeSize&&(typeSize+="</span>");

reclog("<span style='color:#0b1'>已打开:"+type+" "+sample+"hz "+bit+"kbps</span>"+typeSize);

//此处创建这些音频可视化图形绘制浏览器支持妥妥的
waveStore.WaveView=Recorder.WaveView({elem:".recwave"});
Expand Down Expand Up @@ -479,7 +489,7 @@
call||(call=function(msg){
msg&&reclog(msg,1);
});
if(rec){
if(rec&&Recorder.IsOpen()){
window.realTimeSendTryReset&&realTimeSendTryReset();

sonicAsync&&sonicAsync.flush();//丢弃不管,省的去同步麻烦
Expand Down

0 comments on commit 72a46ea

Please sign in to comment.