优化录音,增加try catch,防止录音设备被占用的时候出现应用crash
authorSnickerSun <scy@incartech.cn>
Thu, 23 Sep 2021 09:35:16 +0000 (17:35 +0800)
committerSnickerSun <scy@incartech.cn>
Thu, 23 Sep 2021 09:35:16 +0000 (17:35 +0800)
app/src/main/java/com/enqualcomm/support/service/Deliver.java

index e195cde..5953703 100644 (file)
@@ -627,22 +627,26 @@ public class Deliver extends AbstractConnectionService {
 
             String recordfilepath = Util.getRecordfilePath(mRuntime, TimeUtil.getSystemTime3());
             int recordtime = Integer.parseInt(paramStringMessage.isFromCache().trim());
-            mSendMSGHandler.post(() -> AudioService.getInstance().startRecord(recordfilepath));
-            mSendMSGHandler.postDelayed(() -> {
-                AudioService.getInstance().stopRecord();
-                ICLogger.i("Monitor Record to send " + recordfilepath);
-                //创建voiceConent并添加到数据
-                /**
-                 *        *        * 1 语音——    1.监听语音      *   2.SOS语音      *      3.扩展
-                 *        *          * 2 图片——  1.签到图片      *   2.指令图片      *   3.设备图片      *   4.扩展
-                 */
-                final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, "123", "0000", recordfilepath, 1, 1);
-                // 把voiceContent拆解成1024的分包
-                Util.parseToVoicePacketSent(voiceContent, 1024);
-                //trigger 分包发送
-                if (CoreService.getInstance().getConnection() != null)
-                    CoreService.getInstance().getConnection().DeliverCMDMessageToSystem("SentVoicePacket", "");
-            }, recordtime * 1000);
+            try { //尝试拦截录音错误,不让程序挂掉
+                mSendMSGHandler.post(() -> AudioService.getInstance().startRecord(recordfilepath));
+                mSendMSGHandler.postDelayed(() -> {
+                    AudioService.getInstance().stopRecord();
+                    ICLogger.i("Monitor Record to send " + recordfilepath);
+                    //创建voiceConent并添加到数据
+                    /**
+                     *        *        * 1 语音——        1.监听语音      *   2.SOS语音      *      3.扩展
+                     *        *          * 2 图片——      1.签到图片      *   2.指令图片      *   3.设备图片      *   4.扩展
+                     */
+                    final VoiceContent voiceContent = VoiceContent.placeHolderOut(CONTACT_CATEGORY_GROUP, "123", "0000", recordfilepath, 1, 1);
+                    // 把voiceContent拆解成1024的分包
+                    Util.parseToVoicePacketSent(voiceContent, 1024);
+                    //trigger 分包发送
+                    if (CoreService.getInstance().getConnection() != null)
+                        CoreService.getInstance().getConnection().DeliverCMDMessageToSystem("SentVoicePacket", "");
+                }, recordtime * 1000);
+            }catch (Exception e){
+                ICLogger.e(e.getMessage(),e);
+            }
             return true;
         }
         return false;