diff --git a/assets/npm-home/hash-history.txt b/assets/npm-home/hash-history.txt index 79601bd..9d79c3c 100644 --- a/assets/npm-home/hash-history.txt +++ b/assets/npm-home/hash-history.txt @@ -1,4 +1,8 @@ [ + { + "sha1": "d7949810ec706e70159f0e09860b6f627197a29d", + "time": "2020-1-16 16:19:04" + }, { "sha1": "faa51e270e00316a1f7c005e526dde26b7ceaef1", "time": "2020-1-15 18:02:58" @@ -14,9 +18,5 @@ { "sha1": "e3d0df0e66aa924cf04a56dafc858c40c6054bf6", "time": "2020-1-14 03:12:04" - }, - { - "sha1": "c4a7d796fe658b33a012e69650d5663f1b6c7471", - "time": "2020-1-14 03:03:00" } ] \ No newline at end of file diff --git a/dist/app-support/app.js b/dist/app-support/app.js index 851564e..10c065f 100644 --- a/dist/app-support/app.js +++ b/dist/app-support/app.js @@ -3,4 +3,4 @@ https://github.com/xiangyuecn/Recorder src: app-support/app.js,app-support/app-ios-weixin-support.js,app-support/app-native-support.js */ -!function(n){"use strict";var t=/MicroMessenger/i.test(navigator.userAgent),e=n.RecordAppBaseFolder||"/Recorder/dist/",o=n.OnRecordAppInstalled,u=[{Key:"Native",Support:function(e){l.AlwaysAppUseJS?e(!1):r.Config.IsApp(e)},CanProcess:function(){return!0},Config:{IsApp:function(e){e(!1)},JsBridgeRequestPermission:function(e,n){n("JsBridgeRequestPermission未实现")},JsBridgeStart:function(e,n,t){t("JsBridgeStart未实现")},JsBridgeStop:function(e,n){n("JsBridgeStop未实现")},paths:[{url:e+"app-support/app-native-support.js",check:function(){return!r.IsInit}}]},ExtendDefault:!0},{Key:"IOS-Weixin",Support:function(e){l.AlwaysUseWeixinJS||!Recorder.Support()?e(t):e(!1)},CanProcess:function(){return!1},Config:{WxReady:function(e){e(null,"未实现IOS-Weixin.Config.WxReady")},DownWxMedia:function(e,n,t){t("下载素材接口DownWxMedia未实现")},paths:[{url:e+"app-support/app-ios-weixin-support.js",check:function(){return!i.IsInit}},{url:e+"engine/beta-amr.js",check:function(){return!Recorder.prototype.amr}}]},ExtendDefault:!0},{Key:"Default",Support:function(e){e(!0)},CanProcess:function(){return!0},Config:{paths:[{url:e+"recorder-core.js",check:function(){return!n.Recorder}},{url:e+"engine/mp3.js",check:function(){return!Recorder.prototype.mp3}}]}}],r=u[0],i=u[1],f=u[2];f.RequestPermission=function(e,n){var t=l.__Rec;t&&(t.close(),l.__Rec=null);var o=Recorder();o.open(function(){e()},n)},f.Start=function(e,n,t){var o=l.__Rec;null!=o&&o.close(),l.__Rec=o=Recorder(e),o.appSet=e,o.open(function(){o.start(),n()},function(e){t(e)})},f.Stop=function(t,n){var o=l.__Rec;if(!o)return Recorder.IsOpen()&&((o=Recorder()).open(),o.close()),void n("未开始录音");var r=function(){for(var e in o.close(),o.set)o.appSet[e]=o.set[e]},e=function(e){r(),n(e),l.__Rec=null};t?o.stop(function(e,n){r(),t(e,n),l.__Rec=null},e):e("仅清理资源")};var l={LM:"2019-10-26 11:23:48",Current:0,IsWx:t,BaseFolder:e,AlwaysUseWeixinJS:!1,AlwaysAppUseJS:!1,Platforms:{Native:r,Weixin:i,Default:f},Js:function(r,i,s,e){var c=(e=e||n).document,a=function(e){if(e>=r.length)i();else{var n=r[e],t=n.url;if(!1!==n.check()){var o=c.createElement("script");o.setAttribute("type","text/javascript"),o.setAttribute("src",t),o.onload=function(){a(e+1)},o.onerror=function(e){s("请求失败:"+(e.message||"-")+","+t)},c.body.appendChild(o)}else a(e+1)}};a(0)},Install:function(t,o){var r=l.__reqs||(l.__reqs=[]);r.push({s:t,f:o}),t=function(){i("s",arguments)},o=function(e,n){i("f",arguments)};var i=function(e,n){for(var t=0;t=r.length)return v.decodeTime=Date.now()-u,void function(){c||(c=Date.now());for(var e=[],n=0;n=f.length)r();else{var e=f[t];R.DownWxMedia({mediaId:e,transform_mediaIds:f.join(","),transform_type:d.type,transform_bitRate:d.bitRate,transform_sampleRate:d.sampleRate},function(e){v.list.push(e),e.duration?r():/amr/i.test(e.mime)?(t++,i()):p("微信服务器返回了未知音频类型:"+e.mime)},function(e){p("下载音频失败:"+e)})}},s=0,c=function(){if(s>=n.length)return v.uploadTime=Date.now()-a,void i();var e=n[s];console.log("微信录音片段"+s+" wx.playVoice({localId:'"+e+"'})"),wx.uploadVoice({localId:e,isShowProgressTips:0,fail:p,success:function(e){var n=e.serverId;console.log("serverId:"+n),f.push(n),s++,c()}})},a=Date.now();c()}else p("仅清理资源")},m=a.timeout;if(a.err)return console.error(a.err,m),void p("录制失败,已录制"+m.length+"分钟,但后面出错:"+a.err);if(m.length&&Date.now()-m[m.length-1].time<900)return g(),void t();c=0,a.wx.stopRecord({fail:p,success:function(e){var n=Date.now();m.push({res:e,duration:n-a.startTime,time:n}),t()}})}else p("未开始录音")}}(),function(){"use strict";var i=RecordApp,e=i.Platforms.Native,s=e.Config;e.IsInit=!0;var f=window.NativeRecordReceivePCM=window.top.NativeRecordReceivePCM=function(e,n){var t=f.rec;if(t){t._appStart||t.envStart(1,n),t._appStart=1;for(var o,r=atob(e),i=r.length,s=new Int16Array(i/2),c=0,a=0,u=0;u+2<=i;a++,u+=2)o=(r.charCodeAt(u)|r.charCodeAt(u+1)<<8)<<16>>16,s[a]=o,c+=Math.abs(o);t.envIn(s,c)}else console.error("未开始录音,但收到Native PCM数据")};e.RequestPermission=function(e,n){s.JsBridgeRequestPermission(e,n)},e.Start=function(e,n,t){f.param=e;var o=Recorder(e);o.set.disableEnvInFix=!0,f.rec=o,i.__Rec=o,s.JsBridgeStart(e,n,t)},e.Stop=function(o,n){var r=function(e){n(e),f.rec=null,i.__Rec=null};s.JsBridgeStop(function(){var n=f.rec;if(f.rec=null,n){console.log("rec encode start: pcm:"+n.recSize+" src:"+n.srcSampleRate+" set:"+JSON.stringify(f.param));var t=function(){for(var e in n.set)f.param[e]=n.set[e]};if(!o)return t(),void r("仅清理资源");n.stop(function(e,n){console.log("rec encode end"),t(),o(e,n),i.__Rec=null},function(e){t(),r(e)})}else r("未开始录音")},r)}}(); \ No newline at end of file +!function(e){"use strict";var t=/MicroMessenger/i.test(navigator.userAgent),n=e.RecordAppBaseFolder||"/Recorder/dist/",o=e.OnRecordAppInstalled,a=[{Key:"Native",Support:function(n){f.AlwaysAppUseJS?n(!1):r.Config.IsApp(n)},CanProcess:function(){return!0},Config:{IsApp:function(n){n(!1)},JsBridgeRequestPermission:function(n,e){e("JsBridgeRequestPermission未实现")},JsBridgeStart:function(n,e,t){t("JsBridgeStart未实现")},JsBridgeStop:function(n,e){e("JsBridgeStop未实现")},paths:[{url:n+"app-support/app-native-support.js",check:function(){return!r.IsInit}}]},ExtendDefault:!0},{Key:"IOS-Weixin",Support:function(n){f.AlwaysUseWeixinJS||!Recorder.Support()?n(t):n(!1)},CanProcess:function(){return!1},Config:{WxReady:function(n){n(null,"未实现IOS-Weixin.Config.WxReady")},DownWxMedia:function(n,e,t){t("下载素材接口DownWxMedia未实现")},paths:[{url:n+"app-support/app-ios-weixin-support.js",check:function(){return!i.IsInit}},{url:n+"engine/beta-amr.js",check:function(){return!Recorder.prototype.amr}}]},ExtendDefault:!0},{Key:"Default",Support:function(n){n(!0)},CanProcess:function(){return!0},Config:{paths:[{url:n+"recorder-core.js",check:function(){return!e.Recorder}},{url:n+"engine/mp3.js",check:function(){return!Recorder.prototype.mp3}}]}}],r=a[0],i=a[1],l=a[2];l.RequestPermission=function(n,e){var t=f.__Rec;t&&(t.close(),f.__Rec=null);var o=Recorder();o.open(function(){n()},e)},l.Start=function(n,e,t){var o=f.__Rec;null!=o&&o.close(),f.__Rec=o=Recorder(n),o.appSet=n,o.open(function(){o.start(),e()},function(n){t(n)})},l.Stop=function(t,e){var o=f.__Rec;if(!o)return Recorder.IsOpen()&&((o=Recorder()).open(),o.close()),void e("未开始录音");var r=function(){for(var n in o.close(),o.set)o.appSet[n]=o.set[n]},n=function(n){r(),e(n),f.__Rec=null};t?o.stop(function(n,e){r(),t(n,e),f.__Rec=null},n):n("仅清理资源")};var f={LM:"2019-10-26 11:23:48",Current:0,IsWx:t,BaseFolder:n,AlwaysUseWeixinJS:!1,AlwaysAppUseJS:!1,Platforms:{Native:r,Weixin:i,Default:l},Js:function(r,i,s,n){var c=(n=n||e).document,u=function(n){if(n>=r.length)i();else{var e=r[n],t=e.url;if(!1!==e.check()){var o=c.createElement("script");o.setAttribute("type","text/javascript"),o.setAttribute("src",t),o.onload=function(){u(n+1)},o.onerror=function(n){s("请求失败:"+(n.message||"-")+","+t)},c.body.appendChild(o)}else u(n+1)}};u(0)},Install:function(t,o){var r=f.__reqs||(f.__reqs=[]);r.push({s:t,f:o}),t=function(){i("s",arguments)},o=function(n,e){i("f",arguments)};var i=function(n,e){for(var t=0;t=r.length)return v.decodeTime=Date.now()-a,void function(){c||(c=Date.now());for(var n=[],e=0;e=l.length)r();else{var n=l[t];R.DownWxMedia({mediaId:n,transform_mediaIds:l.join(","),transform_type:d.type,transform_bitRate:d.bitRate,transform_sampleRate:d.sampleRate},function(n){v.list.push(n),n.duration?r():/amr/i.test(n.mime)?(t++,i()):p("微信服务器返回了未知音频类型:"+n.mime)},function(n){p("下载音频失败:"+n)})}},s=0,c=function(){if(s>=e.length)return v.uploadTime=Date.now()-u,void i();var n=e[s];console.log("微信录音片段"+s+" wx.playVoice({localId:'"+n+"'})"),wx.uploadVoice({localId:n,isShowProgressTips:0,fail:p,success:function(n){var e=n.serverId;console.log("serverId:"+e),l.push(e),s++,c()}})},u=Date.now();c()}else p("仅清理资源")},m=u.chunks;if(u.chunkErr)return console.error(u.chunkErr,m),void p("录制失败,已录制"+m.length+"分钟,但后面出错:"+u.chunkErr);if(m.length&&Date.now()-m[m.length-1].time<900)return console.error("丢弃结尾未停止太短录音"),g(),void o();u.stopJoinEnd=function(n,e){u.stopJoinEnd=null;var t=Date.now();n.localId?m.push({res:n,duration:t-u.startTime,time:t,from:e}):console.error("已忽略"+e+"数据",n),u.chunks=null,o()},u.wx.stopRecord({fail:p,success:function(n){u.stopJoinEnd&&u.stopJoinEnd(n,"stop")}})}else p("未开始录音")}}(),function(){"use strict";var i=RecordApp,n=i.Platforms.Native,s=n.Config;n.IsInit=!0;var l=window.NativeRecordReceivePCM=window.top.NativeRecordReceivePCM=function(n,e){var t=l.rec;if(t){t._appStart||t.envStart(1,e),t._appStart=1;for(var o,r=atob(n),i=r.length,s=new Int16Array(i/2),c=0,u=0,a=0;a+2<=i;u++,a+=2)o=(r.charCodeAt(a)|r.charCodeAt(a+1)<<8)<<16>>16,s[u]=o,c+=Math.abs(o);t.envIn(s,c)}else console.error("未开始录音,但收到Native PCM数据")};n.RequestPermission=function(n,e){s.JsBridgeRequestPermission(n,e)},n.Start=function(n,e,t){l.param=n;var o=Recorder(n);o.set.disableEnvInFix=!0,l.rec=o,i.__Rec=o,s.JsBridgeStart(n,e,t)},n.Stop=function(o,e){var r=function(n){e(n),l.rec=null,i.__Rec=null};s.JsBridgeStop(function(){var e=l.rec;if(l.rec=null,e){console.log("rec encode start: pcm:"+e.recSize+" src:"+e.srcSampleRate+" set:"+JSON.stringify(l.param));var t=function(){for(var n in e.set)l.param[n]=e.set[n]};if(!o)return t(),void r("仅清理资源");e.stop(function(n,e){console.log("rec encode end"),t(),o(n,e),i.__Rec=null},function(n){t(),r(n)})}else r("未开始录音")},r)}}(); \ No newline at end of file diff --git a/src/app-support/app-ios-weixin-support.js b/src/app-support/app-ios-weixin-support.js index 9a17cbe..f84f776 100644 --- a/src/app-support/app-ios-weixin-support.js +++ b/src/app-support/app-ios-weixin-support.js @@ -79,6 +79,9 @@ var killStart=function(call){ setTimeout(call,300); }); }; +var timeLog=function(msg){ + console.log("["+Date.now()+"]"+msg); +}; platform.Start=function(set,success,fail){ var wx=WXRecordData.wx; if(!wx){ @@ -112,6 +115,7 @@ platform.Start=function(set,success,fail){ isWaitStart=0; WXRecordData.startTime=Date.now(); WXRecordData.start=set; + timeLog("已开始录音"); success(); } ,fail:startFail @@ -119,14 +123,29 @@ platform.Start=function(set,success,fail){ }); //监听超时自动停止后接续录音 - WXRecordData.timeout=[]; - WXRecordData.err=""; + WXRecordData.chunks=[]; + WXRecordData.chunkErr=""; + WXRecordData.stopJoinEnd=null; wx.onVoiceRecordEnd({ complete:function(res){ var t1=Date.now(); - WXRecordData.timeout.push({res:res,duration:t1-WXRecordData.startTime,time:t1}); + if(WXRecordData.stopJoinEnd){ + //正在进行stop调用时发生了onVoiceRecordEnd,此时不会触发stop回调,需要手动触发 + WXRecordData.stopJoinEnd(res,"chunk"); + }else{ + if(res.localId && WXRecordData.chunks){ + WXRecordData.chunks.push({res:res,duration:t1-WXRecordData.startTime,time:t1,from:"chunk"}); + }else{ + //已彻底停止录音了,就不要塞数据了,丢弃 + console.error("已忽略chunk数据",res); + }; + }; - console.log("微信录音超时,正在重启..."); + timeLog("微信录音超时,正在重启..."); + if(!isStart){ + console.error("已停止录音,拒绝重启"); + return; + }; wx.startRecord({ success:function(){ WXRecordData.startTime=Date.now(); @@ -135,13 +154,16 @@ platform.Start=function(set,success,fail){ ,fail:function(o){ var msg="无法接续录音:"+o.errMsg; console.error(msg,o); - WXRecordData.err=msg; + WXRecordData.chunkErr=msg; } }); } }); }; platform.Stop=function(successx,failx){ + isStart=0; + timeLog("开始停止录音"); + var fail=function(msg){ failx("录音失败:"+(msg.errMsg||msg)); }; @@ -205,7 +227,7 @@ platform.Stop=function(successx,failx){ }; var data=list[deidx]; - data.duration=timeouts[deidx].duration; + data.duration=chunkList[deidx].duration; data.isAmr=true; var bstr=atob(data.data),n=bstr.length,u8arr=new Uint8Array(n); while(n--){ @@ -237,10 +259,11 @@ platform.Stop=function(successx,failx){ }; var upIds=[]; - for(var i=0;i