[Modify]声音签名修改
This commit is contained in:
@@ -82,7 +82,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
Locale.getDefault(),
|
||||
"%ds / %ds",
|
||||
0,
|
||||
audioCard.second ?: 60
|
||||
MAX_RECORD_VOICE_DURATION
|
||||
)
|
||||
binding.tvSoundTime.text = showStr
|
||||
soundViewModel.audioState = SoundViewModel.STATE_RECORD_SAVE_SUCCESS
|
||||
@@ -111,7 +111,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
|
||||
private fun setListener() {
|
||||
binding.ivSoundStatus.setOnClickListener(this)//中间按钮
|
||||
binding.ivSaveRecord.setOnClickListener(this)//保存按钮
|
||||
binding.frSaveRecord.setOnClickListener(this)//保存按钮
|
||||
binding.frDeleteBg.setOnClickListener(this)//删除按钮
|
||||
binding.frRestartBg.setOnClickListener(this)//重新录制按钮
|
||||
}
|
||||
@@ -143,6 +143,10 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
refreshListenerButton(it)
|
||||
}
|
||||
|
||||
soundViewModel.resetStatusLiveData.observe(this) {
|
||||
resetStatus()
|
||||
}
|
||||
|
||||
soundViewModel.showCountDownLiveData.observe(this) {
|
||||
showCountDown(it)
|
||||
}
|
||||
@@ -251,7 +255,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
soundViewModel.clickCenterIcon()
|
||||
}
|
||||
}
|
||||
R.id.ivSaveRecord -> {//保存按钮
|
||||
R.id.frSaveRecord -> {//保存按钮
|
||||
finishRecord()
|
||||
}
|
||||
R.id.frDeleteBg -> {//删除按钮
|
||||
@@ -306,6 +310,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
when (state) {
|
||||
SoundViewModel.STATE_RECORD_NORMAL -> {
|
||||
MAX_RECORD_VOICE_DURATION = 60
|
||||
binding.roundProgress.setProgress(0)
|
||||
binding.roundProgress.setTotalProgress(60)
|
||||
binding.ivSoundStatus.post { binding.ivSoundStatus.setImageResource(R.drawable.ic_prepare_record) }
|
||||
binding.tvRecordTip.text = getString(R.string.start_record)
|
||||
@@ -316,12 +321,12 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
MAX_RECORD_VOICE_DURATION
|
||||
)
|
||||
binding.tvSoundTime.text = showStr
|
||||
binding.ivSoundStatus.post { binding.ivSoundStatus.setImageResource(R.drawable.ic_prepare_record) }
|
||||
binding.groupRsRecord.visibility = View.INVISIBLE
|
||||
binding.groupSaveSound.visibility = View.INVISIBLE
|
||||
binding.groupDeleteSound.visibility = View.INVISIBLE
|
||||
binding.tvUnderReview.visibility = View.INVISIBLE
|
||||
stopSvga()
|
||||
binding.roundProgress.setProgress(0)
|
||||
mCountDownTime = 0
|
||||
}
|
||||
SoundViewModel.STATE_RECORD_RECORDING -> {
|
||||
@@ -378,6 +383,9 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
}, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始录音
|
||||
*/
|
||||
private fun startChronometer() {
|
||||
binding.tvSoundTime.onChronometerTickListener =
|
||||
OnChronometerTickListener { chronometer: Chronometer ->
|
||||
@@ -401,6 +409,9 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
binding.tvSoundTime.start()
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止录音
|
||||
*/
|
||||
private fun stopChronometer() {
|
||||
val showStr = String.format(
|
||||
Locale.getDefault(),
|
||||
@@ -429,22 +440,28 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
||||
} else {
|
||||
stopSvga()
|
||||
}
|
||||
binding.roundProgress.setProgress(0)
|
||||
val showStr = String.format(
|
||||
Locale.getDefault(),
|
||||
"%ds / %ds",
|
||||
0,
|
||||
MAX_RECORD_VOICE_DURATION
|
||||
)
|
||||
binding.tvSoundTime.text = showStr
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetStatus(){
|
||||
binding.roundProgress.setProgress(0)
|
||||
val showStr = String.format(
|
||||
Locale.getDefault(),
|
||||
"%ds / %ds",
|
||||
0,
|
||||
MAX_RECORD_VOICE_DURATION
|
||||
)
|
||||
binding.tvSoundTime.text = showStr
|
||||
}
|
||||
|
||||
private fun stopSvga() {
|
||||
binding.svgRecorder.stopAnimation()
|
||||
binding.svgRecorder.clear()
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始试听
|
||||
*/
|
||||
private fun showCountDown(duration: Int) {
|
||||
if (duration <= MAX_RECORD_VOICE_DURATION) {
|
||||
val showStr = String.format(
|
||||
|
@@ -14,7 +14,6 @@ import com.yizhuan.erban.base.BaseViewModel
|
||||
import com.yizhuan.xchat_android_core.audio.AudioPlayAndRecordManager
|
||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager
|
||||
import com.yizhuan.xchat_android_core.sound.model.SoundModel
|
||||
import com.yizhuan.xchat_android_core.utils.Logger
|
||||
import com.yizhuan.xchat_android_core.utils.toast
|
||||
import com.yizhuan.xchat_android_library.common.application.BaseApp
|
||||
import com.yizhuan.xchat_android_library.utils.ResUtil
|
||||
@@ -60,6 +59,9 @@ class SoundViewModel : BaseViewModel() {
|
||||
private val _refreshPlayStatusLiveData = MutableLiveData<Boolean>()
|
||||
val refreshPlayStatusLiveData: MutableLiveData<Boolean> = _refreshPlayStatusLiveData
|
||||
|
||||
private val _resetStatusLiveData = MutableLiveData<String?>()
|
||||
val resetStatusLiveData: MutableLiveData<String?> = _resetStatusLiveData
|
||||
|
||||
private val _showCountDownLiveData = MutableLiveData<Int>()
|
||||
val showCountDownLiveData: MutableLiveData<Int> = _showCountDownLiveData
|
||||
|
||||
@@ -178,6 +180,8 @@ class SoundViewModel : BaseViewModel() {
|
||||
* 显示默认状态,即初始状态
|
||||
*/
|
||||
fun showNormalState() {
|
||||
// 正在播放:停止播放
|
||||
AudioPlayerHelper.get().endPlay()
|
||||
audioState = STATE_RECORD_NORMAL
|
||||
audioUrl = null
|
||||
audioDur = 0
|
||||
@@ -207,7 +211,6 @@ class SoundViewModel : BaseViewModel() {
|
||||
|
||||
fun reRecord() {
|
||||
if (audioState == STATE_RECORD_SUCCESS || audioState == STATE_RECORD_SAVE_SUCCESS || audioState == STATE_RECORD_AUDIT_SUCCESS) {
|
||||
AudioPlayerHelper.get().endPlay()
|
||||
showNormalState() // 点击重录,回到初始状态
|
||||
}
|
||||
}
|
||||
@@ -307,6 +310,7 @@ class SoundViewModel : BaseViewModel() {
|
||||
|
||||
override fun onCompletion() {
|
||||
_refreshPlayStatusLiveData.value = false// 播放完成:停止状态(播放按钮)
|
||||
_resetStatusLiveData.value = null
|
||||
}
|
||||
})
|
||||
_refreshPlayStatusLiveData.value = true// 点击试听按钮此时并没有正在播放声音,则播放声音并显示正在播放状态(暂停按钮)
|
||||
|
Reference in New Issue
Block a user