Commit 989bd14e by 范玉宾

fix time off switch sound sequence err

Took 2 hours 51 minutes
parent d6e9d2a8
......@@ -284,8 +284,6 @@ class PlayMeditationActivity : BaseActivity() {
)
if (!mediaListLink.isNullOrBlank()) {
ChooseMusicActivity.launch(this, H5Params(mediaListLink,"") )
// val chooseMusicDialog = ChooseMusicDialog(this,H5Params(mediaListLink!!, null))
// chooseMusicDialog.show()
}
}
......@@ -571,7 +569,7 @@ class PlayMeditationActivity : BaseActivity() {
updateUI(needRefresh = false)
initMediaPlayer(mMediaUrl, currentPosition, mMediaIdFromLocal == mMediaId)
initMediaPlayer(mMediaUrl, 0, mMediaIdFromLocal == mMediaId)
} else {
ToastUtil.toastShort("暂无内容")
}
......@@ -621,7 +619,7 @@ class PlayMeditationActivity : BaseActivity() {
updateUI(needRefresh = false)
initMediaPlayer(mMediaUrl, currentPosition, mMediaIdFromLocal == mMediaId)
initMediaPlayer(mMediaUrl, 0, mMediaIdFromLocal == mMediaId)
} else {
ToastUtil.toastShort("暂无内容")
}
......@@ -734,30 +732,9 @@ class PlayMeditationActivity : BaseActivity() {
if (isLoop){
if (isSingle || meditations.size == 1){
MediaPlayerManager
.getInstance(this)?.setAudioPath(currentMeditation?.mediaUrl?:"",isLoop = true)
MediaPlayerManager.getInstance(this)?.setAudioPath(mMediaUrl)
}else{
currentMeditationIndex = meditations.indexOf(currentMeditation)
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)
switchSound()
}
}
......@@ -772,6 +749,38 @@ class PlayMeditationActivity : BaseActivity() {
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) {
......@@ -787,7 +796,7 @@ class PlayMeditationActivity : BaseActivity() {
val currentPosition = mMediaPlayer?.currentPosition
duration = mMediaPlayer?.duration ?: 0
if (current > 0) {
if (current >= 0) {
seekbar_play_progress.max = duration
seekbar_play_progress.progress = current
exo_position.text = MediaPlayerTimeUtil.calculateTime(current)
......
......@@ -45,7 +45,7 @@ class MediaPlayerManager private constructor() {
mTime = time
}
fun setAudioPath(path: String,isLoop:Boolean = false){
fun setAudioPath(path: String){
val attrs = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
......@@ -60,9 +60,6 @@ class MediaPlayerManager private constructor() {
mMediaPlayer?.prepareAsync()
mMediaPlayer?.setOnPreparedListener {
listener?.onPrepared(it)
if (isLoop){
mMediaPlayer?.seekTo(0)
}
}
}
......
......@@ -28,7 +28,7 @@ class MediaPlayerTimeUtil {
"$minute:$second"
}
}
}else if (time in 1..59){
}else if (time in 0..59){
second = time
return if (second in 0..9){
"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