lmw
2024-12-24 bfd1ad288092a4b4a010ea230466f5e86a4e3de4
app/src/main/java/com/sinata/xqmuse/MainActivity.kt
@@ -49,7 +49,7 @@
    var teacherVideoView:VideoView? = null
    private var bgPlayer:AudioUtils? = null//背景音乐播放器
    private var thinkBgPlayer:AudioUtils? = null//冥想背景音播放器
    private var thinkPlayer:AudioUtils? = null//冥想背景音播放器
//    private var thinkPlayer:AudioUtils? = null//冥想背景音播放器
    private var guideAudio:String? = null
    private var guidePlayer:AudioUtils? = null//引导音频播放器
@@ -91,13 +91,13 @@
            if (playing){
                player_play.setImageResource(R.mipmap.player_pause)
                thinkBgPlayer?.resume()
                thinkPlayer?.resume()
//                thinkPlayer?.resume()
                thinkHandler?.sendEmptyMessage(MSG_PROGRESS)
                startTime = System.currentTimeMillis()
            }else{
                player_play.setImageResource(R.mipmap.player_start)
                thinkBgPlayer?.pause()
                thinkPlayer?.pause()
//                thinkPlayer?.pause()
                thinkHandler?.removeMessages(MSG_PROGRESS)
                saveThinkRecord()
            }
@@ -184,30 +184,11 @@
        if (voice?.meditationMusicList?.isNullOrEmpty() == false){
            if (thinkBgPlayer == null){
                thinkBgPlayer = AudioUtils()
                thinkPlayer = AudioUtils()
                thinkBgPlayer!!.setOnAudioStatusUpdateListener(this)
                thinkPlayer!!.setOnAudioStatusUpdateListener(object :AudioUtils.OnAudioStatusUpdateListener{
                    override fun onUpdate(db: Double, time: Long) {
                    }
                    override fun onStop(filePath: String?) {
                    }
                    override fun onStartPlay() {
                    }
                    override fun onFinishPlay() {
                        EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_THINK))
                    }
                    override fun onGetDuration(duration: Int) {
                    }
                })
            }
            val volume = SPUtils.instance().getInt(Const.User.VOLUME_THINK,50)
            thinkPlayer?.setVolume(volume.toFloat()/100)
            thinkBgPlayer?.setVolume(volume.toFloat()/100)
            thinkBgPlayer?.startPlayMusic(this, voice?.meditationMusicList?.get(index))
            thinkPlayer?.startPlayMusic(this, voice?.tutorAudioUrl)
            currentDuration = voice?.meditationSecondList?.get(index)?:0
            EventBus.getDefault().post(EmptyEvent(Const.EventCode.GOT_THINK_DURATION))
            playing = true
@@ -230,7 +211,6 @@
        index = 0
        finishTime = 0L
        thinkBgPlayer?.stopPlayMusic(true)
        thinkPlayer?.stopPlayMusic(true)
        playing = false
        thinkHandler?.removeMessages(0)
        cl_player.gone()
@@ -379,19 +359,17 @@
            player_play.callOnClick()
        }else if(e.code == Const.EventCode.CHANGE_THINK_VOLUME){
            val v = SPUtils.instance().getInt(Const.User.VOLUME_THINK,50)
            thinkPlayer?.setVolume(v.toFloat()/100)
            thinkBgPlayer?.setVolume(v.toFloat()/100)
        }else if(e.code == Const.EventCode.START_GUIDE_AUDIO){
            inGuide = true
            startGuide()
            bgPlayer?.pause()
            thinkBgPlayer?.pause()
            thinkPlayer?.pause()
        }else if(e.code == Const.EventCode.FINISH_GUIDE_AUDIO){
            inGuide = false
            guidePlayer?.stopPlayMusic(false)
            if (voice!=null&& playing){
                thinkBgPlayer?.resume()
                thinkPlayer?.resume()
            }
            if (voice == null)
                bgPlayer?.resume()
@@ -480,11 +458,13 @@
        }else{//顺序
            index++
            if (index>=voice?.meditationMusicList?.size?:0)//列表已播完
                index = 0
            currentDuration = voice?.meditationSecondList?.get(index)?:0
            EventBus.getDefault().post(EmptyEvent(Const.EventCode.GOT_THINK_DURATION))
            if (playing)
                thinkBgPlayer?.startPlayMusic(this, voice?.meditationMusicList?.get(index))
                EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_THINK))
            else{
                currentDuration = voice?.meditationSecondList?.get(index)?:0
                EventBus.getDefault().post(EmptyEvent(Const.EventCode.GOT_THINK_DURATION))
                if (playing)
                    thinkBgPlayer?.startPlayMusic(this, voice?.meditationMusicList?.get(index))
            }
        }
    }
@@ -503,7 +483,7 @@
        var voice: VoiceDetail? = null //冥想详情
        var index = 0 //当前播放序号
        var currentDuration = 0 //当前音频长度(秒)
        var currentPosition = 0 //当前音频进度(秒)
        var currentPosition = 0L //当前音频进度(毫秒)
        var finishTime = 0L //自动结束的时间戳
    }
}