|
@@ -68,6 +68,13 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
|
|
|
private lateinit var receiver: PhoneStateReceiver
|
|
|
|
|
|
+ //当前播放留言状态: 0-无,1-个人留言,2-群留言
|
|
|
+ private var imPlayState = 0
|
|
|
+ //群留言列表
|
|
|
+ private var channelImList = ArrayList<ChannelImDO>()
|
|
|
+ //当前播放的群留言id
|
|
|
+ private var channelImId = 0
|
|
|
+
|
|
|
private var warningTips = false
|
|
|
private val keepHandler: Handler = object : Handler(Looper.getMainLooper()) {
|
|
|
override fun handleMessage(msg: Message) {
|
|
@@ -294,17 +301,16 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
val channelData = Gson().fromJson(tcpModel.data.toString(), ChannelImDO::class.java)
|
|
|
if (!DeviceChannel.calling && !RecordHelper.getInstance().isRecording) {
|
|
|
//群留言
|
|
|
- showMessage("播放留言...")
|
|
|
playChannelVoiceMsg(channelData)
|
|
|
- }
|
|
|
|
|
|
- val imTcpModel = ChannelImUtil.channelImRead(Constants.deviceId, channelData)
|
|
|
- NettyClient.instance.sendMsg(imTcpModel.toJson()).subscribe {
|
|
|
- if (it) {
|
|
|
- Log.d(TAG, "TCP.发送消息完成")
|
|
|
- } else {
|
|
|
- Log.e(TAG, "TCP.发送消息失败")
|
|
|
- HandleTcpConnect.instance.tcpReConnectWithMsgShow()
|
|
|
+ val imTcpModel = ChannelImUtil.channelImRead(Constants.deviceId, channelData)
|
|
|
+ NettyClient.instance.sendMsg(imTcpModel.toJson()).subscribe {
|
|
|
+ if (it) {
|
|
|
+ Log.d(TAG, "TCP.发送消息完成")
|
|
|
+ } else {
|
|
|
+ Log.e(TAG, "TCP.发送消息失败")
|
|
|
+ HandleTcpConnect.instance.tcpReConnectWithMsgShow()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else if (tcpModel.action == TcpAction.IMAction.MSG) {
|
|
@@ -338,7 +344,6 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
EventBus.getDefault().post(MessageEvent(tcpModel, Constants.EVENT_UPDATE_EVENT))
|
|
|
}
|
|
|
} else {
|
|
|
- showMessage("播放留言...")
|
|
|
val interaction = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
playVoiceMsg(interaction)
|
|
|
val msgTcpModel = ImUtil.imRead(Constants.deviceId, interaction.fromDeviceId, interaction.id)
|
|
@@ -591,6 +596,22 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
|
|
|
//留言播放完成
|
|
|
Constants.EVENT_IM_PLAY_DONE -> {
|
|
|
+ //将播放完成的群留言从列表中删除
|
|
|
+ val iterator = channelImList.iterator()
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ val it = iterator.next()
|
|
|
+ if (it.id.equals(channelImId)) {
|
|
|
+ iterator.remove()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //群留言列表还有留言则继续播放
|
|
|
+ if (channelImList.size > 0) {
|
|
|
+ imPlayState = 2
|
|
|
+ channelImId = channelImList.get(0).id
|
|
|
+ MediaPlayHelper.getInstance().playUrlMusic(ApiManager.urlManager.device_url + channelImList.get(0).audioPath, 1f, false)
|
|
|
+ } else {
|
|
|
+ imPlayState = 0
|
|
|
+ }
|
|
|
ImPlayDialogHelper.dismissIMDialog()
|
|
|
}
|
|
|
}
|
|
@@ -667,9 +688,12 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
|
|
|
private fun playVoiceMsg(interactionVO: InteractionVO) {
|
|
|
synchronized(this) {
|
|
|
+ channelImList.clear()
|
|
|
+ showMessage("播放留言...")
|
|
|
MediaPlayHelper.getInstance().stopMusic(true)
|
|
|
SoundPoolManager.getInstance().playSound(1)
|
|
|
AppTool.Time.delay(1000) {
|
|
|
+ imPlayState = 1
|
|
|
MediaPlayHelper.getInstance().playUrlMusic(ApiManager.urlManager.device_url + interactionVO.data, 1f, false)
|
|
|
}
|
|
|
}
|
|
@@ -677,9 +701,18 @@ class WdKeepAliveService : AbsWorkService() {
|
|
|
|
|
|
private fun playChannelVoiceMsg(channelImDO: ChannelImDO) {
|
|
|
synchronized(this) {
|
|
|
- MediaPlayHelper.getInstance().stopMusic(true)
|
|
|
- SoundPoolManager.getInstance().playSound(4)
|
|
|
+ //如果当前正在播放留言则将新的群留言加入待播放留言列表
|
|
|
+ if ((imPlayState == 2 || imPlayState == 1) && MediaPlayHelper.getInstance().isMediaPlaying()) {
|
|
|
+ channelImList.add(channelImDO)
|
|
|
+ } else {
|
|
|
+ imPlayState = 2
|
|
|
+ showMessage("播放群留言...")
|
|
|
+ MediaPlayHelper.getInstance().stopMusic(true)
|
|
|
+ SoundPoolManager.getInstance().playSound(4)
|
|
|
+ }
|
|
|
+
|
|
|
AppTool.Time.delay(1000) {
|
|
|
+ channelImId = channelImDO.id
|
|
|
MediaPlayHelper.getInstance().playUrlMusic(ApiManager.urlManager.device_url + channelImDO.audioPath, 1f, false)
|
|
|
}
|
|
|
}
|