Skip to content

Commit

Permalink
微信JsSDK 录音60秒限制
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Apr 24, 2019
1 parent d23c73f commit be0c733
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app-support-sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ IOS其他浏览器||

## 限制功能

- `IOS-Weixin`不支持实时回调因此当在IOS微信上录音时,实时音量反馈、实时波形等功能不会有效果,并且微信素材下载接口下载的amr音频音质勉强能听(总比没有好,自行实现时也许可以使用它的高清接口,不过需要服务器端转码)。
- `IOS-Weixin`不支持实时回调`微信JsSDK`限制录音最长为60秒;因此当在IOS微信上录音时,实时音量反馈、实时波形等功能不会有效果,录音超过60秒还未调用`Stop`进行停止录音时,停止时也仅仅会返回60秒录音;并且微信素材下载接口下载的amr音频音质勉强能听(总比没有好,自行实现时也许可以使用它的高清接口,不过需要服务器端转码)。
- 如果开启了`Native`支持,并且环境支持App原生录音,`Recorder`对象将不可用,因为不会加载`Recorder`库。


Expand Down Expand Up @@ -257,7 +257,7 @@ IOS-Weixin底层会把从微信素材下载过来的原始音频信息存储在s

需提供`WxReady``DownWxMedia`方法,具体情况请查阅[src/app-support/app.js](https://github.com/xiangyuecn/Recorder/blob/master/src/app-support/app.js)内有详细的说明。

- `WxReady`: 对使用到的[微信JsSDK进行签名](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115),至少要包含`startRecord,stopRecord,uploadVoice`接口。签名操作需要后端支持。
- `WxReady`: 对使用到的[微信JsSDK进行签名](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115),至少要包含`startRecord,stopRecord,onVoiceRecordEnd,uploadVoice`接口。签名操作需要后端支持。
- `DownWxMedia`: 对[微信录音素材进行下载](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738727),下载操作需要后端支持。

以上两个方法都是公众(订阅)号开发范畴,需要注册开通相应的微信服务账号。
Expand Down
2 changes: 1 addition & 1 deletion dist/app-support/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 53 additions & 35 deletions src/app-support/app-ios-weixin-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,34 @@ platform.RequestPermission=function(success,fail){
});
};
platform.Start=function(set,success,fail){
WXRecordData.start=set;

WXRecordData.wx.startRecord({
success:function(){
WXRecordData.start=set;
success();
}
,fail:function(o){
fail("无法录音:"+o.errMsg);
}
});

//监听超时自动停止
WXRecordData.timeout=null;
WXRecordData.wx.onVoiceRecordEnd({
complete:function(res){
WXRecordData.timeout=res;
}
});
};
platform.Stop=function(success,fail){
platform.Stop=function(success,failx){
var fail=function(msg){
fail("录音失败:"+(msg.errMsg||msg));
failx("录音失败:"+(msg.errMsg||msg));
};
var set=WXRecordData.start;
if(!set){
fail("未开始录音");
return;
};
WXRecordData.start=null;

//格式转换
var transform=function(data,sevType,sevDuration){
Expand Down Expand Up @@ -95,39 +107,45 @@ platform.Stop=function(success,fail){
};
};

var stopFn=function(res){
var localId=res.localId;
console.log("微信录音 wx.playVoice({localId:'"+localId+"'})");
wx.uploadVoice({
localId:localId
,isShowProgressTips:0
,fail:fail
,success:function(res){
var serverId=res.serverId;
console.log("微信录音serverId:"+serverId);

config.DownWxMedia({
mediaId:serverId
,type:set.type
},function(data){
//写到set里面,方便调试
set.DownWxMediaData=data;

if(new RegExp(set.type,"i").test(data.mime)){
transform(data.data,set.type,data.duration);
}else if(/amr/i.test(data.mime)){
transform(data.data);
}else{
fail("微信服务器返回了未知音频类型:"+data.mime);
};
},function(msg){
fail("下载音频失败:"+msg);
});
}
});
};

if(WXRecordData.timeout){
stopFn(WXRecordData.timeout);
return;
};
WXRecordData.wx.stopRecord({
fail:fail
,success:function(res){
var localId=res.localId;
console.log("微信录音 wx.playVoice({localId:'"+localId+"'})");
wx.uploadVoice({
localId:localId
,isShowProgressTips:0
,fail:fail
,success:function(res){
var serverId=res.serverId;
console.log("微信录音serverId:"+serverId);

config.DownWxMedia({
mediaId:serverId
,type:set.type
},function(data){
//写到set里面,方便调试
set.DownWxMediaData=data;

if(new RegExp(set.type,"i").test(data.mime)){
transform(data.data,set.type,data.duration);
}else if(/amr/i.test(data.mime)){
transform(data.data);
}else{
fail("微信服务器返回了未知音频类型:"+data.mime);
};
},function(msg){
fail("下载音频失败:"+msg);
});
}
});
}
,success:stopFn
});
};
})();

0 comments on commit be0c733

Please sign in to comment.