12
12
import android .os .CountDownTimer ;
13
13
import android .os .Environment ;
14
14
import android .content .Context ;
15
+
16
+ import java .util .Date ;
15
17
import java .util .UUID ;
16
18
import java .io .FileInputStream ;
17
19
import java .io .File ;
@@ -35,23 +37,23 @@ public class AudioRecorderAPI extends CordovaPlugin {
35
37
private CallbackContext callbackContext ;
36
38
private static final String LOG_TAG = "CordovaPermissionHelper" ;
37
39
public static final int PERMISSION_DENIED_ERROR = 20 ;
40
+ private long lastBeginRecord = 0L ;
38
41
39
42
@ Override
40
43
public boolean execute (String action , JSONArray args , final CallbackContext callbackContext ) throws JSONException {
41
44
Context context = cordova .getActivity ().getApplicationContext ();
42
45
this .callbackContext = callbackContext ;
43
- if (args .length () >= 1 ) {
44
- this .seconds = args .getInt (0 );
45
- } else {
46
- this .seconds = 7 ;
47
- }
48
46
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 ();
50
53
return true ;
51
54
}
52
55
53
56
if (action .equals ("stop" )) {
54
- countDowntimer .cancel ();
55
57
stopRecord (callbackContext );
56
58
return true ;
57
59
}
@@ -186,6 +188,7 @@ public void record() {
186
188
// cordova.getThreadPool().execute(new Runnable() {
187
189
// public void run() {
188
190
try {
191
+ lastBeginRecord = (new Date ()).getTime ();
189
192
myRecorder .prepare ();
190
193
myRecorder .start ();
191
194
} catch (final Exception e ) {
@@ -212,6 +215,9 @@ public void onFinish() {
212
215
213
216
private void stopRecord (final CallbackContext callbackContext ) {
214
217
try {
218
+ long curTime = (new Date ()).getTime ();
219
+ if (curTime - lastBeginRecord < 1000 ) return ;
220
+ countDowntimer .cancel ();
215
221
myRecorder .stop ();
216
222
myRecorder .release ();
217
223
cordova .getThreadPool ().execute (new Runnable () {
0 commit comments