@@ -39,6 +39,7 @@ public class VoiceController {
39
39
private static String mFileName = null ;
40
40
private static String mUsername = null ;
41
41
42
+ public static final int SEND_THRESHOLD = 5000 ;
42
43
public static final int MAX_TIME = 10000 ;
43
44
public static final int INTERVAL = 50 ;
44
45
@@ -261,61 +262,69 @@ public synchronized static void stopRecording(Activity activity, boolean send) {
261
262
}
262
263
263
264
private synchronized static void sendVoiceMessage (final Activity activity ) {
264
- new AsyncTask <Void , Void , String >() {
265
+ int maxVolume = mEnvelopeView .getMaxVolume ();
266
+ SurespotLog .v (TAG , "max recorded volume: %d" , maxVolume );
267
+ if (maxVolume < SEND_THRESHOLD ) {
268
+ Utils .makeToast (activity , activity .getString (R .string .no_audio_detected ));
269
+ }
270
+ else {
271
+ new AsyncTask <Void , Void , String >() {
265
272
266
- @ Override
267
- protected String doInBackground (Void ... params ) {
268
- // convert to AAC
269
- FileInputStream fis ;
270
- try {
271
- fis = new FileInputStream (mFileName );
273
+ @ Override
274
+ protected String doInBackground (Void ... params ) {
275
+ // convert to AAC
276
+ FileInputStream fis ;
277
+ try {
278
+ fis = new FileInputStream (mFileName );
272
279
273
- String outFile = File .createTempFile ("record" , ".aac" ).getAbsolutePath ();
274
- mEncoder .init (16000 , 1 , mSampleRate , 16 , outFile );
280
+ String outFile = File .createTempFile ("record" , ".aac" ).getAbsolutePath ();
281
+ mEncoder .init (16000 , 1 , mSampleRate , 16 , outFile );
275
282
276
- mEncoder .encode (Utils .inputStreamToBytes (fis ));
277
- mEncoder .uninit ();
283
+ mEncoder .encode (Utils .inputStreamToBytes (fis ));
284
+ mEncoder .uninit ();
278
285
279
- // convert to m4a (gingerbread can't play the AAC for some bloody reason).
280
- final String m4aFile = File .createTempFile ("record" , ".m4a" ).getAbsolutePath ();
281
- new AACToM4A ().convert (activity , outFile , m4aFile );
286
+ // convert to m4a (gingerbread can't play the AAC for some bloody reason).
287
+ final String m4aFile = File .createTempFile ("record" , ".m4a" ).getAbsolutePath ();
288
+ new AACToM4A ().convert (activity , outFile , m4aFile );
282
289
283
- // delete files
284
- new File (outFile ).delete ();
285
- new File (mFileName ).delete ();
290
+ // delete files
291
+ new File (outFile ).delete ();
292
+ new File (mFileName ).delete ();
286
293
287
- return m4aFile ;
294
+ return m4aFile ;
288
295
289
- }
296
+ }
290
297
291
- catch (IOException e ) {
292
- SurespotLog .w (TAG , e , "sendVoiceMessage" );
298
+ catch (IOException e ) {
299
+ SurespotLog .w (TAG , e , "sendVoiceMessage" );
300
+ }
301
+ return null ;
293
302
}
294
- return null ;
295
- }
296
303
297
- protected void onPostExecute (final String encryptedVoiceMessageFile ) {
298
- if (encryptedVoiceMessageFile != null ) {
304
+ protected void onPostExecute (final String encryptedVoiceMessageFile ) {
305
+ if (encryptedVoiceMessageFile != null ) {
299
306
300
- ChatUtils .uploadVoiceMessageAsync (activity , MainActivity .getChatController (), MainActivity .getNetworkController (),
301
- Uri .fromFile (new File (encryptedVoiceMessageFile )), mUsername , new IAsyncCallback <Boolean >() {
307
+ ChatUtils .uploadVoiceMessageAsync (activity , MainActivity .getChatController (), MainActivity .getNetworkController (),
308
+ Uri .fromFile (new File (encryptedVoiceMessageFile )), mUsername , new IAsyncCallback <Boolean >() {
302
309
303
- @ Override
304
- public void handleResponse (Boolean result ) {
305
- if (result ) {
306
- // delete m4a
307
- new File (encryptedVoiceMessageFile ).delete ();
310
+ @ Override
311
+ public void handleResponse (Boolean result ) {
312
+ if (result ) {
313
+ // delete m4a
314
+ new File (encryptedVoiceMessageFile ).delete ();
315
+ }
308
316
}
309
- }
310
- });
317
+ });
311
318
312
- }
313
- else {
314
- Utils .makeToast (activity , "error sending message" );
315
- }
319
+ }
320
+ else {
321
+ Utils .makeToast (activity , "error sending message" );
322
+ }
316
323
317
- };
318
- }.execute ();
324
+ };
325
+
326
+ }.execute ();
327
+ }
319
328
320
329
}
321
330
0 commit comments