From ab2842d427504c531c79ddb9c5a9ef1df7833014 Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期四, 06 二月 2025 10:11:44 +0800 Subject: [PATCH] save --- app/src/main/java/com/sinata/xqmuse/MainActivity.kt | 68 ++++++++++++--------------------- 1 files changed, 25 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/sinata/xqmuse/MainActivity.kt b/app/src/main/java/com/sinata/xqmuse/MainActivity.kt index 7cf6d92..74da337 100644 --- a/app/src/main/java/com/sinata/xqmuse/MainActivity.kt +++ b/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() } @@ -165,13 +165,15 @@ } private fun startBgm() { - val bgm = SPUtils.instance().getString(Const.User.BGM) - if (!bgm.isNullOrEmpty()){ - if (bgPlayer == null) - bgPlayer = AudioUtils() - val volume = SPUtils.instance().getInt(Const.User.VOLUME,50) - bgPlayer?.setVolume(volume.toFloat()/100) - bgPlayer?.loopPlayMusic(this,bgm) + HttpManager.getHomeBackgroundMusicByUserId().request(this){_,data-> + if (!data?.audioFile.isNullOrEmpty()){ + if (bgPlayer == null) + bgPlayer = AudioUtils() + val volume = SPUtils.instance().getInt(Const.User.VOLUME,50) + bgPlayer?.setVolume(volume.toFloat()/100) + bgPlayer?.loopPlayMusic(this,data?.audioFile) + } + (fragments[0] as HomeFragment).changeBg(data?.imageUrl?:"") } } @@ -184,30 +186,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,12 +213,11 @@ index = 0 finishTime = 0L thinkBgPlayer?.stopPlayMusic(true) - thinkPlayer?.stopPlayMusic(true) playing = false thinkHandler?.removeMessages(0) cl_player.gone() (fragments[0] as HomeFragment).refreshTodayPlayingState() //对比当前音频是否是每日疗愈 - if (JkApplication.isForeground){ + if (XQApplication.isForeground){ if (isBGMChanged) //BGM已经被切换,重新播放新BGM startBgm() else //BGM未改变,直接续播 @@ -361,7 +343,8 @@ tab_bar.currentTab = 3 onTabSelect(3) }else if(e.code == Const.EventCode.APP_FOREGROUND){ - bgPlayer?.resume() + if (voice==null) + bgPlayer?.resume() }else if(e.code == Const.EventCode.APP_BACKGROUND){ bgPlayer?.pause() }else if(e.code == Const.EventCode.CHANGE_BGM){ @@ -369,7 +352,6 @@ startBgm() else isBGMChanged = true //正在播放疗愈,无法立即切换背景音乐 - (fragments[0] as HomeFragment).changeBg() }else if(e.code == Const.EventCode.START_THINK){ startThink() }else if(e.code == Const.EventCode.FINISH_THINK){ @@ -378,19 +360,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() @@ -479,11 +459,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)) + } } } @@ -502,7 +484,7 @@ var voice: VoiceDetail? = null //冥想详情 var index = 0 //当前播放序号 var currentDuration = 0 //当前音频长度(秒) - var currentPosition = 0 //当前音频进度(秒) + var currentPosition = 0L //当前音频进度(毫秒) var finishTime = 0L //自动结束的时间戳 } } \ No newline at end of file -- Gitblit v1.7.1