[BugFix]解决试听声音只能到59秒的bug

This commit is contained in:
wushaocheng
2023-01-16 01:24:41 +08:00
parent 44da35d193
commit eb43a6c1b8
4 changed files with 18 additions and 12 deletions

View File

@@ -409,7 +409,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
} }
} }
private fun stopSvga(){ private fun stopSvga() {
binding.svgRecorder.stopAnimation() binding.svgRecorder.stopAnimation()
binding.svgRecorder.clear() binding.svgRecorder.clear()
} }

View File

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

View File

@@ -10,7 +10,6 @@ import com.yizhuan.erban.R
import com.yizhuan.erban.audio.SoundSignatureActivity import com.yizhuan.erban.audio.SoundSignatureActivity
import com.yizhuan.erban.audio.helper.AudioPlayerHelper import com.yizhuan.erban.audio.helper.AudioPlayerHelper
import com.yizhuan.erban.audio.helper.OnPlayListener import com.yizhuan.erban.audio.helper.OnPlayListener
import com.yizhuan.erban.audio.presenter.RecordingVoicePresenter
import com.yizhuan.erban.base.BaseViewModel import com.yizhuan.erban.base.BaseViewModel
import com.yizhuan.xchat_android_core.audio.AudioPlayAndRecordManager import com.yizhuan.xchat_android_core.audio.AudioPlayAndRecordManager
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager import com.yizhuan.xchat_android_core.manager.AvRoomDataManager
@@ -22,7 +21,6 @@ import com.yizhuan.xchat_android_library.utils.ResUtil
import com.yizhuan.xchat_android_library.utils.SingleToastUtil import com.yizhuan.xchat_android_library.utils.SingleToastUtil
import com.yizhuan.xchat_android_library.utils.log.MLog import com.yizhuan.xchat_android_library.utils.log.MLog
import java.io.File import java.io.File
import kotlin.math.roundToInt
/** /**
* @author wushaocheng * @author wushaocheng
@@ -135,7 +133,7 @@ class SoundViewModel : BaseViewModel() {
recordType: RecordType recordType: RecordType
) { ) {
val dura = audioLength.toDouble() / 1000 val dura = audioLength.toDouble() / 1000
audioDur = dura.roundToInt() audioDur = dura.toInt()
audioFile = file audioFile = file
Log.d( Log.d(
TAG, "onRecordSuccess : " + file.path TAG, "onRecordSuccess : " + file.path
@@ -224,7 +222,7 @@ class SoundViewModel : BaseViewModel() {
} }
// 正在播放:停止播放 // 正在播放:停止播放
AudioPlayerHelper.get().onPause() AudioPlayerHelper.get().onPause()
if(audioState != STATE_RECORD_NORMAL) { if (audioState != STATE_RECORD_NORMAL) {
_refreshPlayStatusLiveData.value = false // onPause() 停止播放并显示停止状态(播放按钮) _refreshPlayStatusLiveData.value = false // onPause() 停止播放并显示停止状态(播放按钮)
} }
} }
@@ -287,7 +285,11 @@ class SoundViewModel : BaseViewModel() {
TAG, TAG,
"duration = $currDuration" "duration = $currDuration"
) )
_showCountDownLiveData.value = (currDuration / 1000).toInt() if ((SoundSignatureActivity.MAX_RECORD_VOICE_DURATION * 1000L) - currDuration <= 500) {
_showCountDownLiveData.value = (currDuration / 1000).toInt() + 1
} else {
_showCountDownLiveData.value = (currDuration / 1000).toInt()
}
} }
override fun onCompletion() { override fun onCompletion() {
@@ -295,7 +297,7 @@ class SoundViewModel : BaseViewModel() {
} }
}) })
_refreshPlayStatusLiveData.value = true// 点击试听按钮此时并没有正在播放声音,则播放声音并显示正在播放状态(暂停按钮) _refreshPlayStatusLiveData.value = true// 点击试听按钮此时并没有正在播放声音,则播放声音并显示正在播放状态(暂停按钮)
}else if(null != audioUrl && audioUrl?.contains("http") == true){ } else if (null != audioUrl && audioUrl?.contains("http") == true) {
MLog.debug(TAG, "play audioUrl: $audioUrl") MLog.debug(TAG, "play audioUrl: $audioUrl")
AudioPlayerHelper.get().playInThread(audioUrl, object : OnPlayListener { AudioPlayerHelper.get().playInThread(audioUrl, object : OnPlayListener {
override fun onError(error: String) { override fun onError(error: String) {
@@ -311,7 +313,11 @@ class SoundViewModel : BaseViewModel() {
TAG, TAG,
"duration = $currDuration" "duration = $currDuration"
) )
_showCountDownLiveData.value = (currDuration / 1000).toInt() if ((SoundSignatureActivity.MAX_RECORD_VOICE_DURATION * 1000L) - currDuration <= 500) {
_showCountDownLiveData.value = (currDuration / 1000).toInt() + 1
} else {
_showCountDownLiveData.value = (currDuration / 1000).toInt()
}
} }
override fun onCompletion() { override fun onCompletion() {

View File

@@ -148,9 +148,9 @@ public class RoundProgressView extends View {
canvas.drawArc(oval, -90, ((float)mProgress / mTotalProgress) * 360, false, mRingPaint); // canvas.drawArc(oval, -90, ((float)mProgress / mTotalProgress) * 360, false, mRingPaint); //
//字体 //字体
String txt = mProgress + "%"; // String txt = mProgress + "%";
mTxtWidth = mTextPaint.measureText(txt, 0, txt.length()); // mTxtWidth = mTextPaint.measureText(txt, 0, txt.length());
canvas.drawText(txt, mXCenter - mTxtWidth / 2, mYCenter + mTxtHeight / 4, mTextPaint); // canvas.drawText(txt, mXCenter - mTxtWidth / 2, mYCenter + mTxtHeight / 4, mTextPaint);
} }
} }
public void setText(String string){ public void setText(String string){