|
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
|
|
import android.content.pm.ActivityInfo
|
|
import android.content.pm.ActivityInfo
|
|
|
import android.os.Build
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
|
|
+import android.text.TextUtils
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
import android.webkit.WebResourceRequest
|
|
import android.webkit.WebResourceRequest
|
|
|
import android.webkit.WebSettings
|
|
import android.webkit.WebSettings
|
|
@@ -14,12 +15,20 @@ import androidx.databinding.DataBindingUtil
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.gyf.immersionbar.BarHide
|
|
import com.gyf.immersionbar.BarHide
|
|
|
import com.gyf.immersionbar.ktx.immersionBar
|
|
import com.gyf.immersionbar.ktx.immersionBar
|
|
|
|
|
+import com.yingyangfly.baselib.db.AppDataBase
|
|
|
|
|
+import com.yingyangfly.baselib.db.VoicePlayerBean
|
|
|
|
|
+import com.yingyangfly.baselib.db.VoicePlayerDao
|
|
|
|
|
+import com.yingyangfly.baselib.ext.toast
|
|
|
|
|
+import com.yingyangfly.baselib.net.BaseObserver
|
|
|
|
|
+import com.yingyangfly.baselib.net.MyRxScheduler
|
|
|
|
|
+import com.yingyangfly.baselib.player.VoicePlayer
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
import com.yingyangfly.baselib.utils.LiveEventBusUtil
|
|
import com.yingyangfly.baselib.utils.LiveEventBusUtil
|
|
|
import com.yingyangfly.baselib.utils.RxBusCodes
|
|
import com.yingyangfly.baselib.utils.RxBusCodes
|
|
|
import com.yingyangfly.baselib.utils.ViewTool
|
|
import com.yingyangfly.baselib.utils.ViewTool
|
|
|
-import com.yingyangfly.baselib.voice.PlayVoice
|
|
|
|
|
import com.yingyangfly.webview.databinding.ActivityBridgeWebBinding
|
|
import com.yingyangfly.webview.databinding.ActivityBridgeWebBinding
|
|
|
|
|
+import com.yingyangfly.webview.net.WebViewServiceFactory
|
|
|
|
|
+import io.reactivex.schedulers.Schedulers
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* BridgeWebview
|
|
* BridgeWebview
|
|
@@ -30,7 +39,9 @@ class BridgeWebActivity : AppCompatActivity() {
|
|
|
private lateinit var binding: ActivityBridgeWebBinding
|
|
private lateinit var binding: ActivityBridgeWebBinding
|
|
|
private lateinit var webSettings: WebSettings
|
|
private lateinit var webSettings: WebSettings
|
|
|
private var url: String = ""
|
|
private var url: String = ""
|
|
|
- private var playVoice: PlayVoice? = null
|
|
|
|
|
|
|
+ private var db: AppDataBase? = null
|
|
|
|
|
+ private var dao: VoicePlayerDao? = null
|
|
|
|
|
+ private var voicePlayer: VoicePlayer? = null
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
@@ -38,8 +49,11 @@ class BridgeWebActivity : AppCompatActivity() {
|
|
|
hideBar(BarHide.FLAG_HIDE_BAR)
|
|
hideBar(BarHide.FLAG_HIDE_BAR)
|
|
|
navigationBarColor(com.yingyangfly.baselib.R.color.transparent)
|
|
navigationBarColor(com.yingyangfly.baselib.R.color.transparent)
|
|
|
}
|
|
}
|
|
|
- playVoice = PlayVoice()
|
|
|
|
|
- playVoice?.setContext(this)
|
|
|
|
|
|
|
+ db = AppDataBase.getInstance(this)
|
|
|
|
|
+ if (db != null) {
|
|
|
|
|
+ dao = db?.getVoicePlayerDao()
|
|
|
|
|
+ }
|
|
|
|
|
+ voicePlayer = VoicePlayer.getInstance(this)
|
|
|
url = intent.getStringExtra("url") ?: ""
|
|
url = intent.getStringExtra("url") ?: ""
|
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_bridge_web)
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_bridge_web)
|
|
|
ViewTool.inflateLayoutPixels(this, binding.root, 1194, 834)
|
|
ViewTool.inflateLayoutPixels(this, binding.root, 1194, 834)
|
|
@@ -116,7 +130,18 @@ class BridgeWebActivity : AppCompatActivity() {
|
|
|
val msg = it.split("voice:")
|
|
val msg = it.split("voice:")
|
|
|
if (msg.isNullOrEmpty().not()) {
|
|
if (msg.isNullOrEmpty().not()) {
|
|
|
if (msg[1].isNullOrEmpty().not()) {
|
|
if (msg[1].isNullOrEmpty().not()) {
|
|
|
- playVoice?.speak(msg[1])
|
|
|
|
|
|
|
+ if (dao != null) {
|
|
|
|
|
+ val voicePlayerBean = dao?.getVoicePlayerBean(msg[1])
|
|
|
|
|
+ if (voicePlayerBean != null && TextUtils.isEmpty(voicePlayerBean.url)
|
|
|
|
|
+ .not()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ voicePlayer?.play(voicePlayerBean.url) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ getWordsUrl(msg[1])
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -124,10 +149,42 @@ class BridgeWebActivity : AppCompatActivity() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取声音 url
|
|
|
|
|
+ */
|
|
|
|
|
+ private fun getWordsUrl(word: String) {
|
|
|
|
|
+ WebViewServiceFactory.getService()
|
|
|
|
|
+ .getVoiceUrl(word)
|
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
|
+ .compose(MyRxScheduler.ioMain(this, false))
|
|
|
|
|
+ .subscribe(object : BaseObserver<String>() {
|
|
|
|
|
+ override fun onSuccess(t: String?) {
|
|
|
|
|
+ t?.let {
|
|
|
|
|
+ if (dao != null) {
|
|
|
|
|
+ val voicePlayerBean = VoicePlayerBean().apply {
|
|
|
|
|
+ words = word
|
|
|
|
|
+ url = it
|
|
|
|
|
+ }
|
|
|
|
|
+ dao?.insert(voicePlayerBean)
|
|
|
|
|
+ }
|
|
|
|
|
+ voicePlayer?.play(it) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onFail(msg: String) {
|
|
|
|
|
+ msg.toast()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
override fun onDestroy() {
|
|
override fun onDestroy() {
|
|
|
destoryWebView()
|
|
destoryWebView()
|
|
|
- if (playVoice != null) {
|
|
|
|
|
- playVoice?.stop()
|
|
|
|
|
|
|
+ if (voicePlayer != null) {
|
|
|
|
|
+ if (voicePlayer!!.isPlaying) {
|
|
|
|
|
+ voicePlayer?.stop()
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
super.onDestroy()
|
|
super.onDestroy()
|
|
|
}
|
|
}
|