|
|
|
@@ -21,11 +21,11 @@ import com.yizhuan.erban.R
|
|
|
|
|
import com.yizhuan.erban.audio.helper.AudioPlayerHelper
|
|
|
|
|
import com.yizhuan.erban.audio.viewmodel.SoundViewModel
|
|
|
|
|
import com.yizhuan.erban.base.BaseViewBindingActivity
|
|
|
|
|
import com.yizhuan.erban.common.widget.dialog.DialogManager.OkCancelDialogListener
|
|
|
|
|
import com.yizhuan.erban.databinding.ActivitySoundSignatureBinding
|
|
|
|
|
import com.yizhuan.erban.ui.widget.dialog.CommonDialog
|
|
|
|
|
import com.yizhuan.xchat_android_core.auth.AuthModel
|
|
|
|
|
import com.yizhuan.xchat_android_core.file.FileModel
|
|
|
|
|
import com.yizhuan.xchat_android_core.room.model.AvRoomModel
|
|
|
|
|
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager
|
|
|
|
|
import com.yizhuan.xchat_android_core.statistic.StatisticManager
|
|
|
|
|
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol
|
|
|
|
|
import com.yizhuan.xchat_android_core.user.bean.UserInfo.SoundBean
|
|
|
|
@@ -35,6 +35,7 @@ import io.reactivex.SingleObserver
|
|
|
|
|
import io.reactivex.disposables.Disposable
|
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author wushaocheng
|
|
|
|
|
* 声音签名
|
|
|
|
@@ -57,6 +58,8 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
|
|
|
|
|
private var mCountDownTime = 0
|
|
|
|
|
|
|
|
|
|
private val timer by lazy { Timer() }
|
|
|
|
|
|
|
|
|
|
override fun init() {
|
|
|
|
|
AudioPlayerHelper.get().onCreate()
|
|
|
|
|
initWhiteTitleBar(getString(R.string.sound_signature))
|
|
|
|
@@ -77,7 +80,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
}
|
|
|
|
|
1 -> {
|
|
|
|
|
MAX_RECORD_VOICE_DURATION = audioCard.second ?: 60
|
|
|
|
|
binding.roundProgress.setTotalProgress(audioCard.second ?: 60)
|
|
|
|
|
binding.roundProgress.setTotalProgress(audioCard.second ?: 60000)
|
|
|
|
|
val showStr = String.format(
|
|
|
|
|
Locale.getDefault(),
|
|
|
|
|
"%ds / %ds",
|
|
|
|
@@ -91,7 +94,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
}
|
|
|
|
|
2 -> {
|
|
|
|
|
MAX_RECORD_VOICE_DURATION = audioCard.second ?: 60
|
|
|
|
|
binding.roundProgress.setTotalProgress(audioCard.second ?: 60)
|
|
|
|
|
binding.roundProgress.setTotalProgress(audioCard.second ?: 60000)
|
|
|
|
|
val showStr = String.format(
|
|
|
|
|
Locale.getDefault(),
|
|
|
|
|
"%ds / %ds",
|
|
|
|
@@ -118,13 +121,13 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
|
|
|
|
|
private fun initModel() {
|
|
|
|
|
soundViewModel.showConfirmLiveData.observe(this) {
|
|
|
|
|
dialogManager.showOkCancelDialog(ResUtil.getString(R.string.erban_audio_recordingvoiceactivity_021),
|
|
|
|
|
true, object : OkCancelDialogListener {
|
|
|
|
|
override fun onCancel() {}
|
|
|
|
|
override fun onOk() {
|
|
|
|
|
AvRoomModel.get().exitRoom(null)
|
|
|
|
|
if (AvRoomDataManager.get()
|
|
|
|
|
.checkIsOnMicByAccount(AuthModel.get().currentUid.toString())
|
|
|
|
|
) {
|
|
|
|
|
toast(getString(R.string.on_the_mic_not_record))
|
|
|
|
|
} else {
|
|
|
|
|
soundViewModel.showRecordingState()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
soundViewModel.refreshLiveData.observe(this) {
|
|
|
|
@@ -166,7 +169,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
SingleToastUtil.showToast(getString(R.string.update_success))
|
|
|
|
|
//设置最大计时数
|
|
|
|
|
MAX_RECORD_VOICE_DURATION = soundViewModel.audioDur
|
|
|
|
|
binding.roundProgress.setTotalProgress(soundViewModel.audioDur)
|
|
|
|
|
binding.roundProgress.setTotalProgress(soundViewModel.audioDur * 1000)
|
|
|
|
|
val intent = Intent()
|
|
|
|
|
intent.putExtra(AUDIO_FILE, soundViewModel.audioUrl)
|
|
|
|
|
intent.putExtra(AUDIO_DURA, soundViewModel.audioDur)
|
|
|
|
@@ -311,7 +314,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
SoundViewModel.STATE_RECORD_NORMAL -> {
|
|
|
|
|
MAX_RECORD_VOICE_DURATION = 60
|
|
|
|
|
binding.roundProgress.setProgress(0)
|
|
|
|
|
binding.roundProgress.setTotalProgress(60)
|
|
|
|
|
binding.roundProgress.setTotalProgress(60000)
|
|
|
|
|
binding.ivSoundStatus.post { binding.ivSoundStatus.setImageResource(R.drawable.ic_prepare_record) }
|
|
|
|
|
binding.tvRecordTip.text = getString(R.string.start_record)
|
|
|
|
|
val showStr = String.format(
|
|
|
|
@@ -399,20 +402,38 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
MAX_RECORD_VOICE_DURATION
|
|
|
|
|
)
|
|
|
|
|
chronometer.text = showStr
|
|
|
|
|
binding.roundProgress.setProgress(second)
|
|
|
|
|
mCountDownTime = second
|
|
|
|
|
binding.roundProgress.setProgress(elapsedMillis.toInt())
|
|
|
|
|
if (second >= MAX_RECORD_VOICE_DURATION) {
|
|
|
|
|
soundViewModel.stopRecord() // 录制时长超过上限时,停止录制
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
binding.tvSoundTime.base = SystemClock.elapsedRealtime()
|
|
|
|
|
binding.tvSoundTime.start()
|
|
|
|
|
// startProgress()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun startProgress() {
|
|
|
|
|
var progress = 0 //进度条进度值
|
|
|
|
|
timer.schedule(object : TimerTask() {
|
|
|
|
|
override fun run() {
|
|
|
|
|
runOnUiThread {
|
|
|
|
|
progress += 10
|
|
|
|
|
if (progress == MAX_RECORD_VOICE_DURATION * 1000) {
|
|
|
|
|
timer.cancel()
|
|
|
|
|
} else {
|
|
|
|
|
binding.roundProgress.setProgress(progress)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, 10, 10) //间隔时间(单位为毫秒)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 停止录音
|
|
|
|
|
*/
|
|
|
|
|
private fun stopChronometer() {
|
|
|
|
|
timer.cancel()
|
|
|
|
|
val showStr = String.format(
|
|
|
|
|
Locale.getDefault(),
|
|
|
|
|
"%ds / %ds",
|
|
|
|
@@ -421,7 +442,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
)
|
|
|
|
|
binding.tvSoundTime.text = showStr
|
|
|
|
|
binding.roundProgress.setProgress(0)
|
|
|
|
|
binding.roundProgress.setTotalProgress(mCountDownTime)
|
|
|
|
|
binding.roundProgress.setTotalProgress(mCountDownTime * 1000)
|
|
|
|
|
MAX_RECORD_VOICE_DURATION = mCountDownTime
|
|
|
|
|
binding.tvSoundTime.stop()
|
|
|
|
|
}
|
|
|
|
@@ -443,7 +464,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun resetStatus(){
|
|
|
|
|
private fun resetStatus() {
|
|
|
|
|
binding.roundProgress.setProgress(0)
|
|
|
|
|
val showStr = String.format(
|
|
|
|
|
Locale.getDefault(),
|
|
|
|
@@ -463,11 +484,16 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
* 开始试听
|
|
|
|
|
*/
|
|
|
|
|
private fun showCountDown(duration: Int) {
|
|
|
|
|
if (duration <= MAX_RECORD_VOICE_DURATION) {
|
|
|
|
|
val dur = if (60000L - duration <= 500) {
|
|
|
|
|
(duration / 1000) + 1
|
|
|
|
|
} else {
|
|
|
|
|
duration / 1000
|
|
|
|
|
}
|
|
|
|
|
if (dur <= MAX_RECORD_VOICE_DURATION) {
|
|
|
|
|
val showStr = String.format(
|
|
|
|
|
Locale.getDefault(),
|
|
|
|
|
"%ds / %ds",
|
|
|
|
|
duration,
|
|
|
|
|
dur,
|
|
|
|
|
MAX_RECORD_VOICE_DURATION
|
|
|
|
|
)
|
|
|
|
|
binding.roundProgress.setProgress(duration)
|
|
|
|
@@ -497,6 +523,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
|
super.onDestroy()
|
|
|
|
|
timer.cancel()
|
|
|
|
|
mCountDownTime = 0
|
|
|
|
|
soundViewModel.releaseResource()
|
|
|
|
|
stopSvga()
|
|
|
|
|