| | |
| | | import android.provider.Settings |
| | | import android.util.Log |
| | | import android.view.View |
| | | import android.view.WindowManager |
| | | import androidx.fragment.app.Fragment |
| | | import androidx.fragment.app.FragmentPagerAdapter |
| | | import cn.sinata.xldutils.gone |
| | |
| | | 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//引导音频播放器 |
| | |
| | | private var thinkHandler:Handler? = null //冥想时间相关 |
| | | private var inGuide = false //true 引导中... |
| | | |
| | | private val isFirst by lazy { intent.getBooleanExtra("isFirst",false) } //首次安装,需要到导师引导页 |
| | | private val isFirst by lazy { intent.getBooleanExtra("isFirst", false) } //首次安装,需要到导师引导页 |
| | | |
| | | private val MSG_PROGRESS = 0//疗愈进度+1 |
| | | private val MSG_TODAY = 1//今日疗愈更新计时 |
| | |
| | | |
| | | override fun initClick() { |
| | | player_close.setOnClickListener { |
| | | TipDialog.show(supportFragmentManager,"是否关闭当前音频?",object :TipDialog.OnClickCallback{ |
| | | TipDialog.show(supportFragmentManager, "是否关闭当前音频?", object : TipDialog.OnClickCallback { |
| | | override fun onOk() { |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_THINK)) |
| | | } |
| | | |
| | | override fun onCancel() { |
| | | } |
| | | },"确认","取消") |
| | | }, "确认", "取消") |
| | | } |
| | | |
| | | cl_player.setOnClickListener { |
| | |
| | | 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() |
| | | } |
| | |
| | | override fun handleMessage(msg: Message) { |
| | | super.handleMessage(msg) |
| | | when(msg.what){ |
| | | MSG_PROGRESS->{ |
| | | currentPosition = thinkBgPlayer?.currentPosition ?:0 |
| | | MSG_PROGRESS -> { |
| | | currentPosition = thinkBgPlayer?.currentPosition ?: 0 |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.GOT_THINK_POSITION)) |
| | | sendEmptyMessageDelayed(MSG_PROGRESS,1000) |
| | | sendEmptyMessageDelayed(MSG_PROGRESS, 1000) |
| | | } |
| | | MSG_COUNTDOWN->{ |
| | | if (System.currentTimeMillis()>= finishTime) |
| | | MSG_COUNTDOWN -> { |
| | | if (System.currentTimeMillis() >= finishTime) |
| | | EventBus.getDefault().post(EmptyEvent(Const.EventCode.FINISH_THINK)) |
| | | else |
| | | sendEmptyMessageDelayed(MSG_COUNTDOWN,1000) |
| | | sendEmptyMessageDelayed(MSG_COUNTDOWN, 1000) |
| | | } |
| | | MSG_TODAY->{ |
| | | MSG_TODAY -> { |
| | | if (System.currentTimeMillis() - lastTodayTime > 60000) { //距离上次刷新过去了1分钟 |
| | | Log.e(Const.Tag,"已经过1分钟,需要重新获取今日疗愈数据") |
| | | Log.e(Const.Tag, "已经过1分钟,需要重新获取今日疗愈数据") |
| | | lastTodayTime = System.currentTimeMillis() |
| | | (fragments[0] as HomeFragment).getToday() |
| | | } |
| | | sendEmptyMessageDelayed(MSG_TODAY,5000) |
| | | sendEmptyMessageDelayed(MSG_TODAY, 5000) |
| | | } |
| | | } |
| | | } |
| | |
| | | if (guidePlayer == null) |
| | | guidePlayer = AudioUtils() |
| | | if (guideAudio.isNullOrEmpty()) |
| | | HttpManager.getPlan().request(this){_,data-> |
| | | HttpManager.getPlan().request(this){ _, data-> |
| | | guideAudio = data |
| | | if (inGuide){ |
| | | guidePlayer?.setVolume(0.6f) |
| | | guidePlayer?.loopPlayMusic(this,data) |
| | | guidePlayer?.loopPlayMusic(this, data) |
| | | } |
| | | } |
| | | else{ |
| | | guidePlayer?.setVolume(0.6f) |
| | | guidePlayer?.loopPlayMusic(this,guideAudio) |
| | | guidePlayer?.loopPlayMusic(this, guideAudio) |
| | | } |
| | | } |
| | | |
| | | 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 ?: "", data?.backUrl ?: "") |
| | | } |
| | | } |
| | | |
| | |
| | | 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) |
| | | val volume = SPUtils.instance().getInt(Const.User.VOLUME_THINK, 50) |
| | | 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 |
| | |
| | | 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未改变,直接续播 |
| | |
| | | return |
| | | val time = ((System.currentTimeMillis() - startTime) / 1000).toInt() |
| | | startTime = 0L |
| | | HttpManager.saveViewingHistory(voice?.id?:"", time).request(this,false,{ _, _-> |
| | | Log.e(Const.Tag,"冥想记录成功:$time 秒") |
| | | }){_,_-> |
| | | Log.e(Const.Tag,"冥想记录失败:$time 秒") |
| | | HttpManager.saveViewingHistory(voice?.id ?: "", time).request(this, false, { _, _ -> |
| | | Log.e(Const.Tag, "冥想记录成功:$time 秒") |
| | | }){ _, _-> |
| | | Log.e(Const.Tag, "冥想记录失败:$time 秒") |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private fun initTab() { |
| | | val titles = arrayListOf("疗愈","课程","","疗愈馆","我的") |
| | | val titles = arrayListOf("疗愈", "课程", "", "疗愈馆", "我的") |
| | | val iconChecked = arrayListOf( |
| | | R.mipmap.home_selected, |
| | | R.mipmap.play_selected, |
| | |
| | | fragments.add(DiscoveryFragment()) |
| | | fragments.add(MineFragment()) |
| | | view_pager.offscreenPageLimit = fragments.size |
| | | view_pager.adapter = object : FragmentPagerAdapter(supportFragmentManager,0) { |
| | | view_pager.adapter = object : FragmentPagerAdapter(supportFragmentManager, 0) { |
| | | override fun getItem(p0: Int): Fragment { |
| | | return fragments[p0] |
| | | } |
| | |
| | | } |
| | | |
| | | @Subscribe |
| | | fun onEvent(e:EmptyEvent){ |
| | | fun onEvent(e: EmptyEvent){ |
| | | if (e.code == Const.EventCode.CHANGE_USER){ |
| | | tab_bar.currentTab = 0 |
| | | onTabSelect(0) |
| | |
| | | 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){ |
| | |
| | | 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){ |
| | |
| | | }else if(e.code == Const.EventCode.PAUSE_OR_RESUME_THINK){ |
| | | 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) |
| | | val v = SPUtils.instance().getInt(Const.User.VOLUME_THINK, 50) |
| | | 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() |
| | |
| | | } |
| | | |
| | | @Subscribe |
| | | fun onIntEvent(e:IntEvent){ |
| | | fun onIntEvent(e: IntEvent){ |
| | | if (e.code == Const.EventCode.THINK_SEEK_PROGRESS){ |
| | | thinkBgPlayer?.seekTo(e.i) |
| | | player_play.callOnClick() |
| | |
| | | val answer = SPUtils.instance().getString(Const.User.ANSWER) |
| | | if (!answer.isNullOrEmpty()){ //已登录并且有答案 |
| | | 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,"私人定制已保存") |
| | | 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() |
| | | }){_,_-> |
| | | }){ _, _-> |
| | | } |
| | | } |
| | | } |
| | |
| | | onTabSelect(2) |
| | | (fragments[2] as TreeFragment).showFirst() |
| | | hasTreeFirstShow = true |
| | | } |
| | | if (XQApplication.finishAnswer){ |
| | | XQApplication.finishAnswer = false |
| | | tab_bar.currentTab = 2 |
| | | onTabSelect(2) |
| | | } |
| | | } |
| | | |
| | |
| | | }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)) |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | var voice: VoiceDetail? = null //冥想详情 |
| | | var index = 0 //当前播放序号 |
| | | var currentDuration = 0 //当前音频长度(秒) |
| | | var currentPosition = 0 //当前音频进度(秒) |
| | | var currentPosition = 0L //当前音频进度(毫秒) |
| | | var finishTime = 0L //自动结束的时间戳 |
| | | } |
| | | } |