Browse Source

<分机呼叫增加语音提示>

weizhengliang 4 years ago
parent
commit
5948572ff3

+ 68 - 0
app/src/main/java/com/wdkl/callingbed2/service/SoundPoolManager.java

@@ -0,0 +1,68 @@
+package com.wdkl.callingbed2.service;
+
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.SoundPool;
+import android.os.Build;
+
+import com.wdkl.callingbed2.MyApplication;
+import com.wdkl.callingbed2.R;
+
+import java.util.HashMap;
+
+public class SoundPoolManager {
+
+    private static SoundPoolManager instance;
+    private SoundPool soundPool;
+    private HashMap<Integer, Integer> soundID = new HashMap<Integer, Integer>();
+    private boolean isLoaded = false;
+
+    public static SoundPoolManager getInstance() {
+        if (instance == null) {
+            instance = new SoundPoolManager();
+        }
+        return instance;
+    }
+
+    public void init() {
+        if(Build.VERSION.SDK_INT > 21){
+            SoundPool.Builder builder = new SoundPool.Builder();
+            //传入音频数量
+            builder.setMaxStreams(2);
+            //AudioAttributes是一个封装音频各种属性的方法
+            AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
+            //设置音频流的合适的属性
+            attrBuilder.setLegacyStreamType(AudioManager.STREAM_SYSTEM);//STREAM_MUSIC
+            //加载一个AudioAttributes
+            builder.setAudioAttributes(attrBuilder.build());
+            soundPool = builder.build();
+        }else{
+            soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 0);
+        }
+
+        //来电
+        soundID.put(1, soundPool.load(MyApplication.getAppContext(), R.raw.incoming_call, 1));
+        //去电
+        soundID.put(2, soundPool.load(MyApplication.getAppContext(), R.raw.outgoing_call, 1));
+        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
+            @Override
+            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
+                isLoaded = true;
+            }
+        });
+    }
+
+    public void playSound(int index) {
+        try {
+            if (isLoaded) {
+                soundPool.play(soundID.get(index), 1, 1, 0, 0, 1);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void release() {
+        soundPool.release();
+    }
+}

+ 10 - 0
app/src/main/java/com/wdkl/callingbed2/ui/CallingBedActivity.java

@@ -66,6 +66,7 @@ import com.wdkl.callingbed2.entity.UdpEntity;
 import com.wdkl.callingbed2.entity.VersionEntity;
 import com.wdkl.callingbed2.receive.AlarmReceiver;
 import com.wdkl.callingbed2.receive.NetworkConnectChangedReceiver;
+import com.wdkl.callingbed2.service.SoundPoolManager;
 import com.wdkl.callingbed2.util.BitmapUtils;
 import com.wdkl.callingbed2.util.DateUtil;
 import com.wdkl.callingbed2.util.DensityUtils;
@@ -586,6 +587,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
         //20190415 waderson  测试
         ScreenManagerUtil.setScreenBrightness(context, 210);
 
+        SoundPoolManager.getInstance().init();
     }
 
     private void setListeners() {
@@ -2103,6 +2105,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
             goneLlRightView(true);
             setDoorLight(serialPortUtil, "200");//门灯红色闪烁  add by waderson 20191119 后来加的门灯控制
             UdpSendUtil.sendCall4(initDataEntity, mainDataEntity);
+            SoundPoolManager.getInstance().playSound(2);
             CALL_STATUS = Constants.SUPPORT_IN_CALL;
             if (null != initDataEntity) {
                 jbVSupport = setJumpingBeans(tvSupportText, initDataEntity.getDeviceBedNum() + "床正在请求增援...");
@@ -2113,6 +2116,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
                 goneLlRightView(true);
                 setDoorLight(serialPortUtil, "200");//门灯红色闪烁  add by waderson 20191119 后来加的门灯控制
                 UdpSendUtil.sendCall4(initDataEntity, mainDataEntity);
+                SoundPoolManager.getInstance().playSound(2);
                 CALL_STATUS = Constants.SUPPORT_IN_CALL;
                 if (null != initDataEntity) {
                     jbVSupport = setJumpingBeans(tvSupportText, initDataEntity.getDeviceBedNum() + "床正在请求增援...");
@@ -2133,6 +2137,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
             //changeTextColor(tvCallCare);
             goneLlRightView(true);
             //sendProtectHelp();//呼叫护工还没有做;这个先预留
+            SoundPoolManager.getInstance().playSound(2);
             CALL_STATUS = Constants.WORK_IN_CALL;
             if (null != initDataEntity) {
                 jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
@@ -2142,6 +2147,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
                 showThisView(vCall);
                 goneLlRightView(true);
                 //sendProtectHelp();//呼叫护工还没有做;这个先预留
+                SoundPoolManager.getInstance().playSound(2);
                 CALL_STATUS = Constants.WORK_IN_CALL;
                 if (null != initDataEntity) {
                     jbVCall = setJumpingBeans(tvCallText, initDataEntity.getDeviceBedNum() + "床正在呼叫护工...");
@@ -2213,6 +2219,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
             setDoorLight(serialPortUtil, "200");//门灯红色闪烁  add by waderson 20191119 后来加的门灯控制
             setCallStatus(serialPortUtil, "1");
             UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
+            SoundPoolManager.getInstance().playSound(2);
             CALL_STATUS = Constants.NURSE_IN_CALL;
             if (null != initDataEntity) {
                 jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
@@ -2225,6 +2232,7 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
                 setDoorLight(serialPortUtil, "200");//门灯红色闪烁  add by waderson 20191119 后来加的门灯控制
                 setCallStatus(serialPortUtil, "1");
                 UdpSendUtil.sendCall1(initDataEntity, mainDataEntity);
+                SoundPoolManager.getInstance().playSound(2);
                 CALL_STATUS = Constants.NURSE_IN_CALL;
                 if (null != initDataEntity) {
                     jbVNurse = setJumpingBeans(tvNurseText, initDataEntity.getDeviceBedNum() + "床已呼叫,等待护士接听中...");
@@ -2439,6 +2447,8 @@ public class CallingBedActivity extends BaseActivity implements ISerialPortBedOn
         stop();
         //=============================================SIP关闭服务===================================//
         SipHelperUtil.getInstance(this).unRegisterSip();
+
+        SoundPoolManager.getInstance().release();
     }
 
     /**

BIN
app/src/main/res/raw/incoming_call.mp3


BIN
app/src/main/res/raw/outgoing_call.mp3