Skip to content

Commit

Permalink
更新demo_UniApp和文档
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Jun 24, 2024
1 parent fe968d1 commit 8806e2d
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 59 deletions.
21 changes: 16 additions & 5 deletions app-support-sample/demo_UniApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ RecordApp.Start({
,audioTrackSet:{echoCancellation:true,noiseSuppression:true,autoGainControl:true}

//Android指定麦克风源(App搭配原生插件、小程序可用),0 DEFAULT 默认音频源,1 MIC 主麦克风,5 CAMCORDER 相机方向的麦,6 VOICE_RECOGNITION 语音识别,7 VOICE_COMMUNICATION 语音通信(带回声消除)
,android_audioSource:7 //提供此配置时优先级比audioTrackSet更高
,android_audioSource:7 //提供此配置时优先级比audioTrackSet更高,默认值为0

//iOS的AVAudioSession setCategory的withOptions参数值(App搭配原生插件可用),取值请参考本文档下面的iosSetDefault_categoryOptions
//,ios_categoryOptions:0x1|0x4|0x8 //0x8是外放,默认值为0x1|0x4不带0x8是听筒播放,等同于下面的setSpeakerOff
});

//App搭配原生插件时尝试切换听筒播放或外放
Expand Down Expand Up @@ -456,7 +459,7 @@ base64解码,将base64字符串转为字符串
var dataMB=new Uint8Array(1*1024*1024); //可选的,假设同时需要传递1MB的数据到renderjs中
var set={ //可选配置
tag:"格式转码" //可选调用标记,抛异常时会添加到错误消息开头,默认为空字符串
,timeout:5000 //可选调用超时,默认5秒超时
,timeout:5000 //可选调用超时,默认5秒超时,-1不超时
,useEval:false //可选是否要通过UniWebViewEval来执行jsCode,默认false使用UniWebViewVueCall来执行jsCode(此时jsCode中的this为renderjs模块的this)
};
try{
Expand All @@ -473,7 +476,7 @@ try{
CallSuccess({abc:123}, new Uint8Array(9).buffer); //可以额外返回一个ArrayBuffer,逻辑层将接收到一个对象 result={ value:{abc:123}, bigBytes:ArrayBuffer }
`, dataMB.buffer);
}catch(e){
result={errMsg:e.message};
result={timeout:!!e.isTimeout, errMsg:e.message};
}
uni.showModal({title:"renderjs调用结果", content:JSON.stringify(result)});
```
Expand All @@ -482,7 +485,7 @@ uni.showModal({title:"renderjs调用结果", content:JSON.stringify(result)});
App 逻辑层中直接调用此页面或组件的WebView renderjs中的eval(componentThis为null时使用UniWebViewActivate切换的页面或组件);要调用renderjs模块vue组件内的方法请用UniWebViewVueCall;如果需要传递大的数据请用bigBytes参数传入一个ArrayBuffer,jsCode中使用BigBytes变量得到这个数据

``` javascript
//调用示例代码,可使用UniWebViewCallAsync简化这些调用
//调用示例代码,非频繁调用时建议使用UniWebViewCallAsync简化这些调用
var cb=RecordApp.UniMainCallBack((data)=>{ //可选的,renderjs执行完成后回调
uni.showModal({title:"收到了renderjs回调", content:JSON.stringify(data)});
});
Expand All @@ -501,7 +504,8 @@ RecordApp.UniWebViewEval(this,`
App 逻辑层中直接调用此页面或组件的renderjs模块vue组件内的方法(componentThis为null时使用UniWebViewActivate切换的页面或组件),jsCode中的this为renderjs模块的this(也可以用This变量)(如需renderjs中调用逻辑层vue实例方法,请直接用$ownerInstance.callMethod即可);如果需要传递大的数据请用bigBytes参数传入一个ArrayBuffer,jsCode中使用BigBytes变量得到这个数据

``` javascript
//调用示例代码,可使用UniWebViewCallAsync简化这些调用
//调用示例代码,非频繁调用时建议使用UniWebViewCallAsync简化这些调用
//jsCode可以传个对象{preCode:"",jsCode:""},preCode相当于UniWebViewEval调用,会在获取到vue上下文前执行,获取失败时jsCode无法执行,preCode中可重新赋值CallErr函数来绑定失败回调
var cb=RecordApp.UniMainCallBack((data)=>{ //可选的,renderjs执行完成后回调
uni.showModal({title:"收到了renderjs回调", content:JSON.stringify(data)});
});
Expand Down Expand Up @@ -557,6 +561,7 @@ RecordApp.UniNativeUtsPlugin={ //目前仅支持原生插件,uts插件不可
//,nativePluginName:"xxx" //可指定插件名字,默认为Recorder-NativePlugin
};

//配置好后可调用RecordApp.UniCheckNativeUtsPluginConfig()来检查配置是否能生效,返回空字符串代表正常,如果无法加载原生录音插件会返回错误消息
//配置好后在调用录音功能时,会使用原生插件来录音
```

Expand All @@ -582,6 +587,12 @@ setSpeakerOff 切换扬声器外放和听筒播放,随时都可以调用;但
参数:{ off:true } //必填,true听筒播放,false扬声器播放
返回:{ } //空对象

iosSetDefault_categoryOptions iOS设置默认值,Android不可调用,为iOS的AVAudioSession setCategory的withOptions参数值;RecordApp.Start开始录音时如果未提供ios_categoryOptions参数,将会使用此默认值,提供了时将赋值给此默认值;setSpeakerOff调用时也会使用到此默认值
参数:{
value:0x1|0x4|0x8 //必填,0x8是外放,默认不带0x8是听筒播放,取值(多选,默认 0x1|0x4):0 什么也不设置,0x1 MixWithOthers,0x2 DuckOthers,0x4 AllowBluetooth,0x8 DefaultToSpeaker,0x11 InterruptSpokenAudioAndMixWithOthers,0x20 AllowBluetoothA2DP,0x40 AllowAirPlay,0x80 OverrideMutedMicrophoneInterruption
}
返回:{ } //空对象

writeFile 数据写入文件,可新建文件、追加写入(文件流写入)
参数:{
path:"文件路径" //必填,支持的路径请参考下面
Expand Down
74 changes: 40 additions & 34 deletions app-support-sample/demo_UniApp/pages.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path" : "pages/recTest/page_index",
"style" : {
"navigationBarTitleText": "RecordApp录音测试 - uni-app"
}
},
"path" : "pages/recTest/page_index",
"style" : {
"navigationBarTitleText": "RecordApp录音测试 - uni-app"
}
},
{
"path" : "pages/recTest/page_index2",
"style" : {
"navigationBarTitleText": "RecordApp新开页面index - uni-app"
}
},
{
"path" : "pages/recTest/page_index2",
"style" : {
"navigationBarTitleText": "RecordApp新开页面index - uni-app"
}
"path" : "pages/recTest/main_recTest",
"style" : {
"navigationBarTitleText": "RecordApp新开页面main - uni-app"
}
},
{
"path" : "pages/recTest/main_recTest",
"style" : {
"navigationBarTitleText": "RecordApp新开页面main - uni-app"
}
"path" : "pages/recTest/page_asr",
"style" : {
"navigationBarTitleText": "RecordApp语音识别ASR - uni-app"
}
},
{
"path" : "pages/recTest/page_asr",
"style" : {
"navigationBarTitleText": "RecordApp语音识别ASR - uni-app"
}
"path" : "pages/recTest/page_i18n",
"style" : {
"navigationBarTitleText": "RecordApp国际化多语言 - uni-app"
}
},
{
"path" : "pages/recTest/page_i18n",
"style" : {
"navigationBarTitleText": "RecordApp国际化多语言 - uni-app"
}
"path" : "pages/recTest/page_nvue",
"style" : {
"navigationBarTitleText": "RecordApp nvue原生页面 - uni-app"
}
},
{
"path" : "pages/recTest/page_nvue",
"style" : {
"navigationBarTitleText": "RecordApp nvue原生页面 - uni-app"
}
"path" : "pages/recTest/page_renderjsOnly",
"style" : {
"navigationBarTitleText": "RecordApp纯renderjs调用 - uni-app"
}
},
{
"path" : "pages/recTest/page_renderjsOnly",
"style" : {
"navigationBarTitleText": "RecordApp纯renderjs调用 - uni-app"
}
"path" : "pages/recTest/page_renderjsWithout",
"style" : {
"navigationBarTitleText": "逻辑层编码UniWithoutAppRenderjs - uni-app"
}
},
{
"path" : "pages/recTest/page_vue3____composition_api",
"style" : {
"navigationBarTitleText": "RecordApp vue3组合式api测试 - uni-app"
}
"path" : "pages/recTest/page_vue3____composition_api",
"style" : {
"navigationBarTitleText": "RecordApp vue3组合式api测试 - uni-app"
}
}
],
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
Expand Down
7 changes: 7 additions & 0 deletions app-support-sample/demo_UniApp/pages/recTest/main_recTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ DCloud 插件市场下载组件: https://ext.dcloud.net.cn/plugin?name=Recorder-

<button size="mini" type="default" @click="loadVConsole">显示vConsole</button>
</view>
<!-- #ifdef APP -->
<view>
<navigator url="page_renderjsWithout" style="display: inline;">
<button size="mini" type="default">逻辑层编码UniWithoutAppRenderjs</button>
</navigator>
</view>
<!-- #endif -->
<button size="mini" type="default" @click="speakerOnClick">切换成扬声器外放</button>
<button size="mini" type="default" @click="speakerOffClick">切换成听筒播放</button>

Expand Down
Loading

0 comments on commit 8806e2d

Please sign in to comment.