From bfd1ad288092a4b4a010ea230466f5e86a4e3de4 Mon Sep 17 00:00:00 2001
From: lmw <125975490@qq.com>
Date: 星期二, 24 十二月 2024 10:09:43 +0800
Subject: [PATCH] fix bug

---
 app/src/main/java/com/sinata/xqmuse/MainActivity.kt |   60 +++++++++++++++++++++++-------------------------------------
 1 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/app/src/main/java/com/sinata/xqmuse/MainActivity.kt b/app/src/main/java/com/sinata/xqmuse/MainActivity.kt
index 1bd9cc8..2792e10 100644
--- a/app/src/main/java/com/sinata/xqmuse/MainActivity.kt
+++ b/app/src/main/java/com/sinata/xqmuse/MainActivity.kt
@@ -1,9 +1,11 @@
 package com.sinata.xqmuse
 
+import android.annotation.SuppressLint
 import android.content.Intent
 import android.os.Handler
 import android.os.Looper
 import android.os.Message
+import android.provider.Settings
 import android.util.Log
 import android.view.View
 import androidx.fragment.app.Fragment
@@ -47,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//引导音频播放器
@@ -89,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()
             }
@@ -182,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
@@ -228,7 +211,6 @@
         index = 0
         finishTime = 0L
         thinkBgPlayer?.stopPlayMusic(true)
-        thinkPlayer?.stopPlayMusic(true)
         playing = false
         thinkHandler?.removeMessages(0)
         cl_player.gone()
@@ -245,7 +227,7 @@
      * 保存冥想记录
      */
     private fun saveThinkRecord() {
-        if (voice == null||startTime == 0L)
+        if (voice == null||startTime == 0L||SPUtils.instance().getString(Const.User.TOKEN).isNullOrEmpty())
             return
         val time = ((System.currentTimeMillis() - startTime) / 1000).toInt()
         startTime = 0L
@@ -359,7 +341,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){
@@ -376,26 +359,24 @@
             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()
         }else if(e.code == Const.EventCode.REFRESH_PRIVATE){ //重新答题后,刷新私人定制
             (fragments[0] as HomeFragment).getPrivacy()
         }else if(e.code == Const.EventCode.THINK_TIMER){ //开启倒计时
-            thinkHandler?.sendEmptyMessage(1)
+            thinkHandler?.sendEmptyMessage(MSG_COUNTDOWN)
         }
     }
 
@@ -407,10 +388,13 @@
         }
     }
 
+    @SuppressLint("HardwareIds")
     private fun checkAnswer() {
         val answer = SPUtils.instance().getString(Const.User.ANSWER)
         if (!answer.isNullOrEmpty()){ //已登录并且有答案
-            HttpManager.saveUserAnswers(Gson().fromJson(answer, ReqAnswer::class.java)).request(this,false,success = { _, _->
+            val reqAnswer = Gson().fromJson(answer, ReqAnswer::class.java)
+            reqAnswer?.device = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
+            HttpManager.saveUserAnswers(reqAnswer).request(this,false,success = { _, _->
                 SPUtils.instance().put(Const.User.ANSWER,"").apply()
                 Log.e(Const.Tag,"私人定制已保存")
                 (fragments[0] as HomeFragment).getPrivacy()
@@ -474,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))
+            }
         }
     }
 
@@ -497,7 +483,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