Skip to content

Commit

Permalink
Android demo 修复多线程下耗时的构造函数没有调用完成就被销毁bug xiangyuecn#46
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Nov 13, 2019
1 parent e323266 commit 2ba6d90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Binary file modified app-support-sample/demo_android/app-debug.apk.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static private void _Start(final Request req){
sampleRate=16000;
}

new RecordApis(req.jsBridge, sampleRate, new Callback<Object, Object>() {
new RecordApis().init(req.jsBridge, sampleRate, new Callback<Object, Object>() {
public Object Call(Object result, Exception hasError) {
if(hasError!=null){
req.jsBridge.Log.e(LogTag, "开始录音失败"+hasError.toString());
Expand Down Expand Up @@ -447,7 +447,11 @@ static private void DestroyCurrent(){
}
static private RecordApis Current;
static private final int SampleRate=44100;
private RecordApis(RecordAppJsBridge main_, int sampleRateReq, Callback<Object, Object> ready){




synchronized private void init(RecordAppJsBridge main_, int sampleRateReq, Callback<Object, Object> ready){
Current=this;
this.main=main_;
this.logData= RecordAppJsBridge.SavePCM_ToLogFile;
Expand Down Expand Up @@ -490,13 +494,17 @@ private RecordApis(RecordAppJsBridge main_, int sampleRateReq, Callback<Object,
ThreadX.Run(new Runnable() {
@Override
public void run() {
readThread=Thread.currentThread();
try {
readAsync();
}catch (Exception e){
main.Log.e(LogTag, "录音中途出现异常:"+e.toString());
if(isRec) {//Sync Check
readThread = Thread.currentThread();
try {
readAsync();
} catch (Exception e) {
if(main!=null) {//Sync Check
main.Log.e(LogTag, "录音中途出现异常:" + e.toString());
}
}
readThread = null;
}
readThread=null;
}
});
}
Expand All @@ -512,7 +520,7 @@ public void run() {
private ByteArrayOutputStream logStreamFull;
private ByteArrayOutputStream logStreamVal;

private void destroy(){
synchronized private void destroy(){
Current=null;

isRec=false;
Expand Down Expand Up @@ -556,7 +564,9 @@ private void alive(){
aliveInt=ThreadX.SetTimeout(10 * 1000, new Runnable() {
@Override
public void run() {
main.Log.e(LogTag, "录音超时自动停止:超过10秒未调用alive");
if(main!=null) {//Sync Check
main.Log.e(LogTag, "录音超时自动停止:超过10秒未调用alive");
}
destroy();
}
});
Expand Down

0 comments on commit 2ba6d90

Please sign in to comment.