Skip to content

Commit 5282121

Browse files
committed
vivo: android record bug
1 parent b822456 commit 5282121

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/android/com/emj365/plugins/AudioRecorderAPI.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import android.os.CountDownTimer;
1313
import android.os.Environment;
1414
import android.content.Context;
15+
16+
import java.util.Date;
1517
import java.util.UUID;
1618
import java.io.FileInputStream;
1719
import java.io.File;
@@ -35,23 +37,23 @@ public class AudioRecorderAPI extends CordovaPlugin {
3537
private CallbackContext callbackContext;
3638
private static final String LOG_TAG = "CordovaPermissionHelper";
3739
public static final int PERMISSION_DENIED_ERROR = 20;
40+
private long lastBeginRecord = 0L;
3841

3942
@Override
4043
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
4144
Context context = cordova.getActivity().getApplicationContext();
4245
this.callbackContext = callbackContext;
43-
if (args.length() >= 1) {
44-
this.seconds = args.getInt(0);
45-
} else {
46-
this.seconds = 7;
47-
}
4846
if (action.equals("record")) {
49-
this.record();
47+
if (args.length() >= 1) {
48+
this.seconds = args.getInt(0);
49+
} else {
50+
this.seconds = 7;
51+
}
52+
this.record();
5053
return true;
5154
}
5255

5356
if (action.equals("stop")) {
54-
countDowntimer.cancel();
5557
stopRecord(callbackContext);
5658
return true;
5759
}
@@ -186,6 +188,7 @@ public void record() {
186188
// cordova.getThreadPool().execute(new Runnable() {
187189
// public void run() {
188190
try {
191+
lastBeginRecord = (new Date()).getTime();
189192
myRecorder.prepare();
190193
myRecorder.start();
191194
} catch (final Exception e) {
@@ -212,6 +215,9 @@ public void onFinish() {
212215

213216
private void stopRecord(final CallbackContext callbackContext) {
214217
try {
218+
long curTime = (new Date()).getTime();
219+
if (curTime - lastBeginRecord < 1000) return;
220+
countDowntimer.cancel();
215221
myRecorder.stop();
216222
myRecorder.release();
217223
cordova.getThreadPool().execute(new Runnable() {

0 commit comments

Comments
 (0)