|
|
@@ -7,12 +7,10 @@ import android.view.View
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.yingyang.moca.R
|
|
|
import com.yingyang.moca.databinding.ActivityMocaBinding
|
|
|
-import com.yingyangfly.baselib.db.VoicePlayerBean
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
|
|
|
-import com.yingyangfly.baselib.player.VoicePlayer
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
import com.yingyangfly.baselib.utils.JumpUtil
|
|
|
import com.yingyangfly.baselib.utils.RxBusCodes
|
|
|
@@ -31,11 +29,9 @@ class MocaActivity : BaseMVVMActivity<ActivityMocaBinding, MocaViewModel>(),
|
|
|
private var reviewTaskId = ""
|
|
|
lateinit var rxTimer: RxTimer
|
|
|
var time: Long = 0
|
|
|
- private var voicePlayer: VoicePlayer? = null
|
|
|
|
|
|
override fun initViews() {
|
|
|
rxTimer = RxTimer()
|
|
|
- voicePlayer = VoicePlayer.getInstance(mContext)
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
@@ -119,62 +115,4 @@ class MocaActivity : BaseMVVMActivity<ActivityMocaBinding, MocaViewModel>(),
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
-
|
|
|
- @Subscribe(code = RxBusCodes.LoadedVoice, threadMode = ThreadMode.MAIN)
|
|
|
- fun speak(str: String) {
|
|
|
- if (db != null) {
|
|
|
- val voicePlayerDao = db?.getVoicePlayerDao()
|
|
|
- if (voicePlayerDao != null) {
|
|
|
- val voicePlayerBean = voicePlayerDao.getVoicePlayerBean(str)
|
|
|
- if (voicePlayerBean != null) {
|
|
|
- if (voicePlayer != null) {
|
|
|
- voicePlayer?.play(voicePlayerBean.url) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- getVoiceUrl(str)
|
|
|
- }
|
|
|
- } else {
|
|
|
- getVoiceUrl(str)
|
|
|
- }
|
|
|
- } else {
|
|
|
- getVoiceUrl(str)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取声音url
|
|
|
- */
|
|
|
- private fun getVoiceUrl(taskDesn: String) {
|
|
|
- viewModel.getVoiceUrl(taskDesn, fail = {
|
|
|
- it.toast()
|
|
|
- }, success = {
|
|
|
- if (TextUtils.isEmpty(it).not()) {
|
|
|
- if (db != null) {
|
|
|
- val voicePlayerDao = db?.getVoicePlayerDao()
|
|
|
- if (voicePlayerDao != null) {
|
|
|
- val voicePlayerBean = VoicePlayerBean().apply {
|
|
|
- url = it
|
|
|
- words = taskDesn
|
|
|
- }
|
|
|
- voicePlayerDao.insert(voicePlayerBean)
|
|
|
- }
|
|
|
- }
|
|
|
- if (voicePlayer != null) {
|
|
|
- voicePlayer?.play(it) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- override fun onDestroy() {
|
|
|
- if (voicePlayer != null && voicePlayer!!.isPlaying) {
|
|
|
- voicePlayer?.stop()
|
|
|
- }
|
|
|
- super.onDestroy()
|
|
|
- }
|
|
|
-
|
|
|
}
|