|
|
@@ -15,10 +15,12 @@ import android.webkit.WebViewClient
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.alibaba.android.arouter.launcher.ARouter
|
|
|
import com.bumptech.glide.Glide
|
|
|
+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.GsonUtil
|
|
|
import com.yingyangfly.baselib.utils.LiveEventBusUtil
|
|
|
@@ -28,6 +30,7 @@ import com.yingyangfly.game.databinding.ActivityPlayGameBinding
|
|
|
import com.yingyangfly.game.dialog.CountdownDialog
|
|
|
import com.yingyangfly.game.dialog.GameResultDialog
|
|
|
import com.yingyangfly.game.entity.GameDataBean
|
|
|
+import com.yingyangfly.game.net.GAME_API
|
|
|
import com.yingyangfly.game.utils.AndroidToJs
|
|
|
import gorden.rxbus2.RxBus
|
|
|
import gorden.rxbus2.Subscribe
|
|
|
@@ -50,6 +53,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
private var gameBackgroundImage = ""
|
|
|
private var gameShortDesn = ""
|
|
|
private lateinit var webSettings: WebSettings
|
|
|
+ private var voicePlayer: VoicePlayer? = null
|
|
|
private var gameResultDialog: GameResultDialog? = null
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
@@ -64,6 +68,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
}
|
|
|
|
|
|
override fun initViews() {
|
|
|
+ voicePlayer = VoicePlayer.getInstance(mContext)
|
|
|
if (TextUtils.isEmpty(url).not()) {
|
|
|
initWebView(url)
|
|
|
}
|
|
|
@@ -72,6 +77,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
}
|
|
|
if (TextUtils.isEmpty(gameShortDesn).not()) {
|
|
|
binding.tvPlay.text = gameShortDesn
|
|
|
+ binding.tvIntroduce.text = gameShortDesn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -298,10 +304,19 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ override fun onPause() {
|
|
|
+ super.onPause()
|
|
|
+ if (voicePlayer != null) {
|
|
|
+ if (voicePlayer!!.isPlaying) {
|
|
|
+ voicePlayer?.stop()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 游戏开始
|
|
|
*/
|
|
|
- fun callStartGame() {
|
|
|
+ private fun callStartGame() {
|
|
|
runOnUiThread {
|
|
|
binding.webView.evaluateJavascript(
|
|
|
"javascript:CallStartGame()"
|
|
|
@@ -355,5 +370,83 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
LiveEventBusUtil.observer<String>(this, RxBusCodes.LOADINGOVER) {
|
|
|
loadingOver = true
|
|
|
}
|
|
|
+
|
|
|
+ //播放语音
|
|
|
+ LiveEventBusUtil.observer<String>(this, RxBusCodes.PLAYVOICE) {
|
|
|
+ if (it.isNullOrEmpty().not()) {
|
|
|
+ val msg = it.split("voice:")
|
|
|
+ if (msg.isNullOrEmpty().not()) {
|
|
|
+ binding.tvIntroduce.text = msg[1]
|
|
|
+ speak(msg[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 语音合成
|
|
|
+ */
|
|
|
+ private fun speak(desn: String) {
|
|
|
+ if (db != null) {
|
|
|
+ val voicePlayerDao = db?.getVoicePlayerDao()
|
|
|
+ if (voicePlayerDao != null) {
|
|
|
+ val voicePlayerBean = voicePlayerDao.getVoicePlayerBean(desn)
|
|
|
+ if (voicePlayerBean != null) {
|
|
|
+ if (voicePlayer != null) {
|
|
|
+ voicePlayer?.play(voicePlayerBean.url) {
|
|
|
+ binding.tvIntroduce.text = gameShortDesn
|
|
|
+ callPlayBgMusic()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ getVoiceUrl(desn)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ getVoiceUrl(desn)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ getVoiceUrl(desn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取声音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) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开启游戏音乐
|
|
|
+ */
|
|
|
+ private fun callPlayBgMusic() {
|
|
|
+ runOnUiThread {
|
|
|
+ binding.webView.evaluateJavascript(
|
|
|
+ "javascript:CallPlayBgMusic()"
|
|
|
+ ) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|