|
|
@@ -1,9 +1,6 @@
|
|
|
package com.yingyangfly.game.play
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
-import android.app.Activity
|
|
|
-import android.app.ActivityManager
|
|
|
-import android.content.Context
|
|
|
import android.content.Intent
|
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
@@ -24,10 +21,8 @@ import com.alibaba.android.arouter.launcher.ARouter
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.yingyangfly.baselib.bean.GameDataBean
|
|
|
import com.yingyangfly.baselib.bean.GetSaveGameRecordBean
|
|
|
-import com.yingyangfly.baselib.db.VoicePlayerBean
|
|
|
import com.yingyangfly.baselib.ext.*
|
|
|
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
|
|
|
@@ -71,7 +66,6 @@ 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
|
|
|
|
|
|
var mWebViewHeight = 0
|
|
|
@@ -91,7 +85,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
}
|
|
|
|
|
|
override fun initViews() {
|
|
|
- voicePlayer = VoicePlayer.getInstance(mContext)
|
|
|
if (TextUtils.isEmpty(url).not()) {
|
|
|
initWebView(url)
|
|
|
}
|
|
|
@@ -316,11 +309,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
|
|
|
override fun onPause() {
|
|
|
super.onPause()
|
|
|
- if (voicePlayer != null) {
|
|
|
- if (voicePlayer!!.isPlaying) {
|
|
|
- voicePlayer?.stop()
|
|
|
- }
|
|
|
- }
|
|
|
+ LiveEventBusUtil.send(RxBusCodes.STOPVOICE, "")
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -393,24 +382,30 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
}
|
|
|
//游戏加载完成
|
|
|
LiveEventBusUtil.observer<String>(this, RxBusCodes.LOADINGOVER) {
|
|
|
- loadingOver = true
|
|
|
- if (countdownSuccess) {
|
|
|
- callStartGame()
|
|
|
+ runOnUiThread {
|
|
|
+ loadingOver = true
|
|
|
+ if (countdownSuccess) {
|
|
|
+ callStartGame()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//播放语音
|
|
|
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])
|
|
|
+ runOnUiThread {
|
|
|
+ if (it.isNullOrEmpty().not()) {
|
|
|
+ val msg = it.split("voice:")
|
|
|
+ if (msg.isNullOrEmpty().not()) {
|
|
|
+ binding.tvIntroduce.text = msg[1]
|
|
|
+ speak(msg[1])
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//游戏超时退出
|
|
|
LiveEventBusUtil.observer<String>(this, RxBusCodes.GAMEOVERTIME) {
|
|
|
- finish()
|
|
|
+ runOnUiThread {
|
|
|
+ finish()
|
|
|
+ }
|
|
|
}
|
|
|
//返回首页结束游戏
|
|
|
LiveEventBusUtil.observer<String>(this, RxBusCodes.CALLQUITGAME) {
|
|
|
@@ -437,63 +432,17 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
setReduce(false)
|
|
|
}
|
|
|
}
|
|
|
+ //播放音乐
|
|
|
+ LiveEventBusUtil.observer<String>(this, RxBusCodes.STARTMUSIC) {
|
|
|
+ callPlayBgMusic()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 语音合成
|
|
|
*/
|
|
|
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) {
|
|
|
- if (isTopActivity(this)) {
|
|
|
- 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) {
|
|
|
- if (isTopActivity(this)) {
|
|
|
- voicePlayer?.play(it) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
+ LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, desn)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -501,11 +450,7 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
*/
|
|
|
private fun callPlayBgMusic() {
|
|
|
runOnUiThread {
|
|
|
- binding.webView.evaluateJavascript(
|
|
|
- "javascript:CallPlayBgMusic()"
|
|
|
- ) {
|
|
|
-
|
|
|
- }
|
|
|
+ binding.webView.evaluateJavascript("javascript:CallPlayBgMusic()") {}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -579,15 +524,6 @@ class PlayGameActivity : BaseMVVMActivity<ActivityPlayGameBinding, PlayGameViewM
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 判断当前activity是否位于栈顶
|
|
|
- */
|
|
|
- private fun isTopActivity(activity: Activity): Boolean {
|
|
|
- val am = activity.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
|
- val cn = am.getRunningTasks(1)[0].topActivity
|
|
|
- return cn!!.className == activity.javaClass.name
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 是否缩放
|
|
|
*/
|