|
@@ -1,8 +1,10 @@
|
|
|
package com.wdkl.ncs.android.component.home.activity
|
|
|
|
|
|
import android.app.Activity
|
|
|
+import android.content.ComponentName
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
+import android.media.AudioManager
|
|
|
import android.os.Bundle
|
|
|
import android.os.CountDownTimer
|
|
|
import android.os.VibrationEffect
|
|
@@ -11,7 +13,9 @@ import android.util.Log
|
|
|
import android.view.KeyEvent
|
|
|
import android.view.View
|
|
|
import com.google.gson.Gson
|
|
|
+import com.wdkl.core.voip.AsyncPlayer
|
|
|
import com.wdkl.ncs.android.component.home.R
|
|
|
+import com.wdkl.ncs.android.component.home.broadcast.MyMediaButtonReceiver
|
|
|
import com.wdkl.ncs.android.component.home.settingconfig.SettingConfig
|
|
|
import com.wdkl.ncs.android.component.home.util.MediaPlayHelper
|
|
|
import com.wdkl.ncs.android.component.nursehome.common.Constants
|
|
@@ -38,6 +42,7 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
private var countdownTime = 15//默认转接时间
|
|
|
private var isAnswerOrHangUp = false//加一个变量防止在最后一秒点击了接听或者挂断 还是会转发出去
|
|
|
lateinit var mVibrator: Vibrator
|
|
|
+// lateinit var asyncPlayer: AsyncPlayer
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
@@ -71,6 +76,8 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
// 是护士才开启自动转接
|
|
|
countDownTimer?.start()
|
|
|
}
|
|
|
+// asyncPlayer = AsyncPlayer(TAG)
|
|
|
+// asyncPlayer.play(this,R.raw.incoming_call,true, AudioManager.STREAM_MUSIC)
|
|
|
MediaPlayHelper.getInstance().playResMusic(R.raw.incoming_call, 1.0f, true)
|
|
|
}
|
|
|
|
|
@@ -81,6 +88,45 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
change_over_relayout.setOnClickListener(this)
|
|
|
hang_up_imagev.setOnClickListener(this)
|
|
|
call_the_voice_imagev.setOnClickListener(this)
|
|
|
+
|
|
|
+ /*
|
|
|
+ val mbr = ComponentName(packageName, MediaButtonReceiver::class.java.getName())
|
|
|
+ val mMediaSession = MediaSessionCompat(this, "mbr", mbr, null)
|
|
|
+ //一定要设置
|
|
|
+ mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS or
|
|
|
+ MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS)
|
|
|
+ if (!mMediaSession.isActive()) {
|
|
|
+ mMediaSession.setActive(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ mMediaSession.setCallback(object : MediaSessionCompat.Callback() {
|
|
|
+ override fun onMediaButtonEvent(intent: Intent): Boolean {
|
|
|
+ val action = intent.action
|
|
|
+ if (action != null) {
|
|
|
+ if (TextUtils.equals(action, Intent.ACTION_MEDIA_BUTTON)) {
|
|
|
+ val keyEvent: KeyEvent = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT)
|
|
|
+ if (keyEvent != null) {
|
|
|
+ if (keyEvent.getAction() === KeyEvent.ACTION_DOWN) {
|
|
|
+ val keyCode: Int = keyEvent.getKeyCode()
|
|
|
+ Log.i(TAG, "keycode " + keyCode)
|
|
|
+ when (keyCode) {
|
|
|
+ KeyEvent.KEYCODE_MEDIA_PLAY -> {
|
|
|
+ answerCall()
|
|
|
+ }
|
|
|
+ KeyEvent.KEYCODE_MEDIA_PAUSE -> {
|
|
|
+ answerCall()
|
|
|
+ }
|
|
|
+ KeyEvent.KEYCODE_MEDIA_NEXT -> {}
|
|
|
+ KeyEvent.KEYCODE_MEDIA_PREVIOUS -> {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onMediaButtonEvent(intent)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
override fun onStart() {
|
|
@@ -90,7 +136,6 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
override fun onClick(p0: View?) {
|
|
|
when(p0?.id){
|
|
|
R.id.change_over_relayout ->{
|
|
@@ -102,31 +147,19 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
val voiceTransferTcpModel = VoiceUtil.voiceTransfer(Integer.parseInt(Constants.deviceId), tcpModel.fromId, interactionVO)
|
|
|
TcpClient.getInstance().sendMsg(voiceTransferTcpModel.toJson())
|
|
|
mVibrator.cancel()
|
|
|
+// asyncPlayer.stop()
|
|
|
finish()
|
|
|
}
|
|
|
R.id.hang_up_imagev ->{
|
|
|
- acceptCall()
|
|
|
+ rejectCall()
|
|
|
}
|
|
|
R.id.call_the_voice_imagev ->{
|
|
|
- isAnswerOrHangUp = true
|
|
|
- MediaPlayHelper.getInstance().stopMusic()
|
|
|
- countDownTimer?.cancel()
|
|
|
- //给服务器发送接听 tcp
|
|
|
- val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
- val voiceUtilTcpModel = VoiceUtil.voiceAccept(Integer.parseInt(Constants.deviceId), tcpModel.fromId, interactionVO.id)
|
|
|
- TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
|
|
|
- mVibrator.cancel()
|
|
|
- val intent = Intent(this, WebRTCVoipAudioActivity::class.java)
|
|
|
- intent.putExtra("targetId", targetId)
|
|
|
- intent.putExtra("TcpModel", tcpModel)
|
|
|
- intent.putExtra(WebRTCVoipAudioActivity().ACTION, WebRTCVoipAudioActivity().CALLING)
|
|
|
- startActivity(intent)
|
|
|
- finish()
|
|
|
+ answerCall()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun acceptCall(){
|
|
|
+ fun rejectCall(){
|
|
|
DeviceChannel.calling = false
|
|
|
isAnswerOrHangUp = true
|
|
|
MediaPlayHelper.getInstance().stopMusic()
|
|
@@ -136,6 +169,25 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
val voiceUtilTcpModel = VoiceUtil.voiceReject(Integer.parseInt(Constants.deviceId), tcpModel.fromId, interactionVO.id)
|
|
|
TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
|
|
|
mVibrator.cancel()
|
|
|
+// asyncPlayer.stop()
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+
|
|
|
+ fun answerCall(){
|
|
|
+// asyncPlayer.stop()
|
|
|
+ isAnswerOrHangUp = true
|
|
|
+ MediaPlayHelper.getInstance().stopMusic()
|
|
|
+ countDownTimer?.cancel()
|
|
|
+ //给服务器发送接听 tcp
|
|
|
+ val interactionVO = Gson().fromJson(tcpModel.data.toString(), InteractionVO::class.java)
|
|
|
+ val voiceUtilTcpModel = VoiceUtil.voiceAccept(Integer.parseInt(Constants.deviceId), tcpModel.fromId, interactionVO.id)
|
|
|
+ TcpClient.getInstance().sendMsg(voiceUtilTcpModel.toJson())
|
|
|
+ mVibrator.cancel()
|
|
|
+ val intent = Intent(this, WebRTCVoipAudioActivity::class.java)
|
|
|
+ intent.putExtra("targetId", targetId)
|
|
|
+ intent.putExtra("TcpModel", tcpModel)
|
|
|
+ intent.putExtra(WebRTCVoipAudioActivity().ACTION, WebRTCVoipAudioActivity().CALLING)
|
|
|
+ startActivity(intent)
|
|
|
finish()
|
|
|
}
|
|
|
|
|
@@ -156,6 +208,7 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
val voiceTransferTcpModel = VoiceUtil.voiceTransfer(Integer.parseInt(Constants.deviceId), tcpModel.fromId, interactionVO)
|
|
|
TcpClient.getInstance().sendMsg(voiceTransferTcpModel.toJson())
|
|
|
mVibrator.cancel()
|
|
|
+// asyncPlayer.stop()
|
|
|
finish()
|
|
|
}
|
|
|
}
|
|
@@ -164,13 +217,10 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
|
|
|
override fun onStop() {
|
|
|
super.onStop()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
|
|
@@ -190,8 +240,6 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
fun onMoonEvent(messageEvent: MessageEvent) {
|
|
|
- Log.i(TAG,"收到tcp"+tcpModel!!.action)
|
|
|
-
|
|
|
if (messageEvent.tag == 2) {
|
|
|
val tcpModel = messageEvent.getMessage() as TcpModel?
|
|
|
Log.i(TAG,"收到tcp"+tcpModel!!.action)
|
|
@@ -200,8 +248,11 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
countDownTimer?.cancel()
|
|
|
MediaPlayHelper.getInstance().stopMusic()
|
|
|
mVibrator.cancel()
|
|
|
+// asyncPlayer.stop()
|
|
|
finish()
|
|
|
}
|
|
|
+ } else if (messageEvent.tag == Constants.EVENT_BLUETOOTH_ACCEPT_CALL){
|
|
|
+ answerCall()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -212,6 +263,7 @@ class WebRTCVoipAudioRingingActivity : Activity(), View.OnClickListener {
|
|
|
if (countDownTimer != null) {
|
|
|
countDownTimer?.cancel()
|
|
|
}
|
|
|
+// asyncPlayer.stop()
|
|
|
MediaPlayHelper.getInstance().stopMusic()
|
|
|
mVibrator.cancel()
|
|
|
EventBus.getDefault().unregister(this)
|