[BugFix]声音签名功能修改

This commit is contained in:
wushaocheng
2023-01-16 20:54:36 +08:00
parent dffb5f81da
commit db8d72614a
5 changed files with 55 additions and 26 deletions

View File

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

View File

@@ -19,7 +19,7 @@ import lombok.Getter;
*/ */
public class AudioPlayerHelper { public class AudioPlayerHelper {
private final static long mIntervalTime = 100L; private final static long mIntervalTime = 10L;
public interface WHAT_STATUS { public interface WHAT_STATUS {
int ERROR = 1; int ERROR = 1;

View File

@@ -115,7 +115,7 @@ class SoundViewModel : BaseViewModel() {
/** /**
* 显示录音中状态 * 显示录音中状态
*/ */
private fun showRecordingState() { fun showRecordingState() {
audioState = STATE_RECORD_RECORDING audioState = STATE_RECORD_RECORDING
_refreshLiveData.value = audioState _refreshLiveData.value = audioState
audioRecorder = audioRecorder =
@@ -301,11 +301,12 @@ class SoundViewModel : BaseViewModel() {
TAG, TAG,
"duration = $currDuration" "duration = $currDuration"
) )
if (60000L - currDuration <= 500) { _showCountDownLiveData.value = currDuration.toInt()
_showCountDownLiveData.value = (currDuration / 1000).toInt() + 1 // if (60000L - currDuration <= 500) {
} else { // _showCountDownLiveData.value = (currDuration / 1000).toInt() + 1
_showCountDownLiveData.value = (currDuration / 1000).toInt() // } else {
} // _showCountDownLiveData.value = (currDuration / 1000).toInt()
// }
} }
override fun onCompletion() { override fun onCompletion() {

View File

@@ -43,7 +43,7 @@ public class RoundProgressView extends View {
// 字的高度 // 字的高度
private float mTxtHeight; private float mTxtHeight;
// 总进度 // 总进度
private int mTotalProgress = 60; private int mTotalProgress = 60000;
// 当前进度 // 当前进度
private int mProgress; private int mProgress;

View File

@@ -5054,5 +5054,6 @@
<string name="recording_sound_card">錄制聲音卡</string> <string name="recording_sound_card">錄制聲音卡</string>
<string name="the_default_dynamic_cannot_be_liked">默認動態不能點贊</string> <string name="the_default_dynamic_cannot_be_liked">默認動態不能點贊</string>
<string name="the_default_dynamic_cannot_be_commented">默認動態不能評論</string> <string name="the_default_dynamic_cannot_be_commented">默認動態不能評論</string>
<string name="on_the_mic_not_record">正在上麥中,不能錄音</string>
</resources> </resources>