|
@@ -1,10 +1,8 @@
|
|
|
package com.yingyangfly.game.dialog
|
|
|
|
|
|
import android.content.Context
|
|
|
-import android.media.AudioAttributes
|
|
|
-import android.media.AudioManager
|
|
|
-import android.media.SoundPool
|
|
|
import android.os.Bundle
|
|
|
+import android.text.TextUtils
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
@@ -14,6 +12,7 @@ import androidx.fragment.app.DialogFragment
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.gyf.immersionbar.BarHide
|
|
|
import com.gyf.immersionbar.ktx.immersionBar
|
|
|
+import com.yingyangfly.baselib.player.VoicePlayer
|
|
|
import com.yingyangfly.baselib.utils.LiveEventBusUtil
|
|
|
import com.yingyangfly.baselib.utils.RxBusCodes
|
|
|
import com.yingyangfly.baselib.utils.RxTimer
|
|
@@ -29,6 +28,9 @@ class CountdownDialog : DialogFragment() {
|
|
|
private lateinit var rxTimer: RxTimer
|
|
|
private var url = ""
|
|
|
private var title: String = ""
|
|
|
+ private var oneStep = ""
|
|
|
+ private var twoStep = ""
|
|
|
+ private var threeStep = ""
|
|
|
private var gameImage: AppCompatImageView? = null
|
|
|
private var imageCountdown: AppCompatImageView? = null
|
|
|
var onDialogClickListener: ((bean: String) -> Unit)? = null
|
|
@@ -36,8 +38,7 @@ class CountdownDialog : DialogFragment() {
|
|
|
private var tvTitle: AppCompatTextView? = null
|
|
|
private var loadingOver = false
|
|
|
private var content: Context? = null
|
|
|
- private var soundPool: SoundPool? = null
|
|
|
- private val soundIdArr = IntArray(3)
|
|
|
+ private var voicePlayer: VoicePlayer? = null
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
@@ -45,9 +46,14 @@ class CountdownDialog : DialogFragment() {
|
|
|
dialog?.setCanceledOnTouchOutside(true)
|
|
|
}
|
|
|
|
|
|
- fun setContentBackground(url: String, title: String) {
|
|
|
+ fun setContentBackground(
|
|
|
+ url: String, title: String, oneStep: String, twoStep: String, threeStep: String
|
|
|
+ ) {
|
|
|
this.url = url
|
|
|
this.title = title
|
|
|
+ this.oneStep = oneStep
|
|
|
+ this.twoStep = twoStep
|
|
|
+ this.threeStep = threeStep
|
|
|
}
|
|
|
|
|
|
override fun onStart() {
|
|
@@ -69,16 +75,7 @@ class CountdownDialog : DialogFragment() {
|
|
|
activity, R.layout.dialog_count_down, container, 2388, 1668
|
|
|
)
|
|
|
content = activity
|
|
|
- // 5.0 及 之后
|
|
|
- soundPool =
|
|
|
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- val audioAttributes: AudioAttributes =
|
|
|
- AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA)
|
|
|
- .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build()
|
|
|
- SoundPool.Builder().setMaxStreams(3).setAudioAttributes(audioAttributes).build()
|
|
|
- } else { // 5.0 以前
|
|
|
- SoundPool(3, AudioManager.STREAM_MUSIC, 0) // 创建SoundPool
|
|
|
- }
|
|
|
+ voicePlayer = VoicePlayer.getInstance(content)
|
|
|
findId(rootView)
|
|
|
initData()
|
|
|
initTimer()
|
|
@@ -96,9 +93,6 @@ class CountdownDialog : DialogFragment() {
|
|
|
|
|
|
private fun initData() {
|
|
|
Glide.with(requireActivity()).asGif().load(R.drawable.fish).into(loadingImage!!)
|
|
|
- soundIdArr[0] = soundPool!!.load(content, R.raw.one, 1)
|
|
|
- soundIdArr[1] = soundPool!!.load(content, R.raw.two, 1)
|
|
|
- soundIdArr[2] = soundPool!!.load(content, R.raw.three, 1)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -114,17 +108,31 @@ class CountdownDialog : DialogFragment() {
|
|
|
when (date.toString()) {
|
|
|
"1" -> {
|
|
|
imageCountdown!!.setBackgroundResource(R.mipmap.icon_one)
|
|
|
- soundPool!!.play(soundIdArr[0], 1f, 1f, 1, 0, 1f)
|
|
|
+ if (voicePlayer != null && TextUtils.isEmpty(oneStep).not()) {
|
|
|
+ imageCountdown!!.post {
|
|
|
+ voicePlayer?.play(oneStep) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
"2" -> {
|
|
|
imageCountdown!!.setBackgroundResource(R.mipmap.icon_two)
|
|
|
- soundPool!!.play(soundIdArr[1], 1f, 1f, 1, 0, 1f)
|
|
|
+ if (voicePlayer != null && TextUtils.isEmpty(twoStep).not()) {
|
|
|
+ imageCountdown!!.post {
|
|
|
+ voicePlayer?.stop()
|
|
|
+ voicePlayer?.play(twoStep) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
"3" -> {
|
|
|
imageCountdown!!.setBackgroundResource(R.mipmap.icon_three)
|
|
|
- soundPool!!.play(soundIdArr[2], 1f, 1f, 1, 0, 1f)
|
|
|
+ if (voicePlayer != null && TextUtils.isEmpty(threeStep).not()) {
|
|
|
+ imageCountdown!!.post {
|
|
|
+ voicePlayer?.stop()
|
|
|
+ voicePlayer?.play(threeStep) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (it == time) {
|
|
@@ -151,9 +159,9 @@ class CountdownDialog : DialogFragment() {
|
|
|
}
|
|
|
|
|
|
override fun dismiss() {
|
|
|
- if (soundPool != null) {
|
|
|
- soundPool?.release()
|
|
|
- }
|
|
|
super.dismiss()
|
|
|
+ if (voicePlayer != null) {
|
|
|
+ voicePlayer?.stop()
|
|
|
+ }
|
|
|
}
|
|
|
}
|