Commit 989bd14e by 范玉宾

fix time off switch sound sequence err

Took 2 hours 51 minutes
parent d6e9d2a8
...@@ -284,8 +284,6 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -284,8 +284,6 @@ class PlayMeditationActivity : BaseActivity() {
) )
if (!mediaListLink.isNullOrBlank()) { if (!mediaListLink.isNullOrBlank()) {
ChooseMusicActivity.launch(this, H5Params(mediaListLink,"") ) ChooseMusicActivity.launch(this, H5Params(mediaListLink,"") )
// val chooseMusicDialog = ChooseMusicDialog(this,H5Params(mediaListLink!!, null))
// chooseMusicDialog.show()
} }
} }
...@@ -571,7 +569,7 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -571,7 +569,7 @@ class PlayMeditationActivity : BaseActivity() {
updateUI(needRefresh = false) updateUI(needRefresh = false)
initMediaPlayer(mMediaUrl, currentPosition, mMediaIdFromLocal == mMediaId) initMediaPlayer(mMediaUrl, 0, mMediaIdFromLocal == mMediaId)
} else { } else {
ToastUtil.toastShort("暂无内容") ToastUtil.toastShort("暂无内容")
} }
...@@ -621,7 +619,7 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -621,7 +619,7 @@ class PlayMeditationActivity : BaseActivity() {
updateUI(needRefresh = false) updateUI(needRefresh = false)
initMediaPlayer(mMediaUrl, currentPosition, mMediaIdFromLocal == mMediaId) initMediaPlayer(mMediaUrl, 0, mMediaIdFromLocal == mMediaId)
} else { } else {
ToastUtil.toastShort("暂无内容") ToastUtil.toastShort("暂无内容")
} }
...@@ -734,30 +732,9 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -734,30 +732,9 @@ class PlayMeditationActivity : BaseActivity() {
if (isLoop){ if (isLoop){
if (isSingle || meditations.size == 1){ if (isSingle || meditations.size == 1){
MediaPlayerManager MediaPlayerManager.getInstance(this)?.setAudioPath(mMediaUrl)
.getInstance(this)?.setAudioPath(currentMeditation?.mediaUrl?:"",isLoop = true)
}else{ }else{
currentMeditationIndex = meditations.indexOf(currentMeditation) switchSound()
if(currentMeditationIndex == meditations.size - 1){
currentMeditationIndex = 0
}else{
currentMeditationIndex++
}
currentMeditation = meditations[currentMeditationIndex]
val event = MeditationEvent(
currentMeditation?.mediaId?.toInt()?:0,
mMeditationId?:0L,
mMeditationType?:0,
mBusinessType,
status = mStatus,
buried = mBuried?:"",
mediaUrl = currentMeditation?.mediaUrl?:"",
mediaCoverUrl = currentMeditation?.coverImageUrl?:"",
title = currentMeditation?.title?:"",
desc = currentMeditation?.desc?:""
)
EventBus.getDefault().post(event)
} }
} }
...@@ -772,6 +749,38 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -772,6 +749,38 @@ class PlayMeditationActivity : BaseActivity() {
mMediaPlayer?.pause() mMediaPlayer?.pause()
} }
} }
mMediaPlayer?.setOnErrorListener { mp, what, extra -> true }
}
private fun switchSound(){
var meditation:MeditationPlayModuleBean.MeditationDetail? = null
meditations?.forEachIndexed { index, meditationDetail ->
if (meditationDetail.mediaId == mMediaId){
currentMeditationIndex = index
}
}
if (mMeditationId == null || mMediaId == null) return
if (currentMeditationIndex < meditations.size - 1) {
meditation = meditations[currentMeditationIndex + 1]
} else {
meditation = meditations[0]
}
currentMeditation = meditation.copy(meditationId = mMeditationId!!)
mMediaId = meditation.mediaId
mMediaCoverUrl = meditation.coverImageUrl
mMediaUrl = meditation.mediaUrl
mStatus = meditation.status
mTitle = meditation.title
mDesc = meditation.title
updateUI(needRefresh = false)
initMediaPlayer(mMediaUrl, 0, mMediaIdFromLocal == mMediaId)
} }
private fun initMediaPlayer(path: String, current: Int, isSameOne: Boolean = false) { private fun initMediaPlayer(path: String, current: Int, isSameOne: Boolean = false) {
...@@ -787,7 +796,7 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -787,7 +796,7 @@ class PlayMeditationActivity : BaseActivity() {
val currentPosition = mMediaPlayer?.currentPosition val currentPosition = mMediaPlayer?.currentPosition
duration = mMediaPlayer?.duration ?: 0 duration = mMediaPlayer?.duration ?: 0
if (current > 0) { if (current >= 0) {
seekbar_play_progress.max = duration seekbar_play_progress.max = duration
seekbar_play_progress.progress = current seekbar_play_progress.progress = current
exo_position.text = MediaPlayerTimeUtil.calculateTime(current) exo_position.text = MediaPlayerTimeUtil.calculateTime(current)
......
...@@ -45,7 +45,7 @@ class MediaPlayerManager private constructor() { ...@@ -45,7 +45,7 @@ class MediaPlayerManager private constructor() {
mTime = time mTime = time
} }
fun setAudioPath(path: String,isLoop:Boolean = false){ fun setAudioPath(path: String){
val attrs = AudioAttributes.Builder() val attrs = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
...@@ -60,9 +60,6 @@ class MediaPlayerManager private constructor() { ...@@ -60,9 +60,6 @@ class MediaPlayerManager private constructor() {
mMediaPlayer?.prepareAsync() mMediaPlayer?.prepareAsync()
mMediaPlayer?.setOnPreparedListener { mMediaPlayer?.setOnPreparedListener {
listener?.onPrepared(it) listener?.onPrepared(it)
if (isLoop){
mMediaPlayer?.seekTo(0)
}
} }
} }
......
...@@ -28,7 +28,7 @@ class MediaPlayerTimeUtil { ...@@ -28,7 +28,7 @@ class MediaPlayerTimeUtil {
"$minute:$second" "$minute:$second"
} }
} }
}else if (time in 1..59){ }else if (time in 0..59){
second = time second = time
return if (second in 0..9){ return if (second in 0..9){
"00:0$second" "00:0$second"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment