Commit 90413816 by 范玉宾

fix play bug

parent c0250f53
......@@ -9,12 +9,12 @@ ext {
"m-consultant" : "0.0.60.25",
"m-fm" : "0.0.30.08",
"m-user" : "0.0.62.19",
"m-home" : "0.0.23.69",
"m-home" : "0.0.23.70",
"m-im" : "0.0.21.44",
"m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.10",
"m-muse" : "0.0.28.51",
"m-muse" : "0.0.28.52",
"m-tests" : "0.0.24.18",
"m-course" : "0.0.43.37",
......@@ -94,7 +94,7 @@ ext {
"m-consultant" : "0.0.60.25",
"m-fm" : "0.0.30.08",
"m-user" : "0.0.62.19",
"m-home" : "0.0.23.69",
"m-home" : "0.0.23.70",
"m-im" : "0.0.21.44",
"m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.8",
......
......@@ -94,6 +94,12 @@ class PlayMeditationActivity : BaseActivity() {
private var broadcastTime = 0
/**
* 传递过来的mediaId 用于判断正在播放的是否是同一条音频
*/
private var mMediaIdFromLocal: Long? = null
override fun onCreate(savedInstanceState: Bundle?) {
setTransparentForImageView(this, null)
statusBarLightMode(this)
......@@ -107,7 +113,7 @@ class PlayMeditationActivity : BaseActivity() {
EventBus.getDefault().register(this)
mMediaId = intent?.getLongExtra("MEDIA_ID", 0L)
mMediaIdFromLocal = intent?.getLongExtra("MEDIA_ID", 0L)
mMeditationId = intent?.getLongExtra("MEDITATION_ID", 0L)
mMeditationType = intent?.getIntExtra("MEDITATION_TYPE", 0)
mMediaUrl = intent?.getStringExtra("MEDIA_URL") ?: ""
......@@ -123,7 +129,7 @@ class PlayMeditationActivity : BaseActivity() {
private fun getData() {
updateUIByMeditationType()
if (mMeditationId == null || (mMediaId == null && mMeditationType != 0)) {
if (mMeditationId == null || (mMediaIdFromLocal == null && mMeditationType != 0)) {
return
}
// 声音详情
......@@ -143,7 +149,7 @@ class PlayMeditationActivity : BaseActivity() {
val mediaList = module.mediaList
if(!mediaList.isNullOrEmpty()){
val meditation = mediaList[0]
currentMeditation = meditation.copy(mMeditationType,mMeditationId)
currentMeditation = meditation.copy(meditationType = mMeditationType,meditationId = mMeditationId!!)
mTitle = meditation.title
mDesc = meditation.desc?:""
mMediaUrl = meditation.mediaUrl
......@@ -155,7 +161,11 @@ class PlayMeditationActivity : BaseActivity() {
updateUI()
initMediaPlayer(mMediaUrl, currentPosition)
initMediaPlayer(
mMediaUrl,
currentPosition,
mMediaIdFromLocal == mMediaId
)
//快进点击事件
ActionCountUtils.baiDuCountSign3(
......@@ -175,7 +185,7 @@ class PlayMeditationActivity : BaseActivity() {
} else {
MuseHttp.getInstance().getMeditationPlayDetail(
meditionType = 1,
mediaId = mMediaId!!,
mediaId = mMediaIdFromLocal!!,
meditationId = mMeditationId!!
)
.subscribeOn(Schedulers.io())
......@@ -196,7 +206,7 @@ class PlayMeditationActivity : BaseActivity() {
if (meditationPlayBean.mediaId == mMediaId) {
currentMeditation =
meditationPlayBean.copy(meditationId = mMeditationId!!)
meditationPlayBean.copy(meditationType = mMeditationType,meditationId = mMeditationId!!)
mMediaId = module?.mediaId ?: 0L
mTitle = meditationPlayBean.title
......@@ -218,7 +228,7 @@ class PlayMeditationActivity : BaseActivity() {
updateUI()
initMediaPlayer(mMediaUrl, currentPosition)
initMediaPlayer(mMediaUrl, currentPosition,mMediaIdFromLocal == mMediaId)
}
}
}
......@@ -553,7 +563,7 @@ class PlayMeditationActivity : BaseActivity() {
updateUI()
initMediaPlayer(mMediaUrl, currentPosition)
initMediaPlayer(mMediaUrl, currentPosition, mMediaIdFromLocal == mMediaId)
} else {
ToastUtil.toastShort("当前已经是第一首")
}
......@@ -592,7 +602,7 @@ class PlayMeditationActivity : BaseActivity() {
updateUI()
initMediaPlayer(mMediaUrl, currentPosition)
initMediaPlayer(mMediaUrl, currentPosition, mMediaIdFromLocal == mMediaId)
} else {
ToastUtil.toastShort("当前已经是最后一首")
}
......@@ -741,15 +751,11 @@ class PlayMeditationActivity : BaseActivity() {
}
}
private fun initMediaPlayer(path: String, current: Int) {
// val event = MeditationFloatEvent(show = false,stop = false,meditation = currentMeditation)
// EventBus.getDefault().post(event)
private fun initMediaPlayer(path: String, current: Int, isSameOne: Boolean = false) {
if (MediaPlayerManager.getInstance(this)?.getAudioPath() != null
&& MediaPlayerManager.getInstance(this)?.getAudioPath() == path
if (MediaPlayerManager.getInstance(this)?.getAudioPath()!=null &&
MediaPlayerManager.getInstance(this)?.getMediaId() == mMediaId
) {
MediaPlayerManager.getInstance(this)?.play()
if (mMediaPlayer?.isPlaying == true) {
exo_play.setImageResource(R.drawable.icon_pause_play)
} else {
......@@ -759,7 +765,6 @@ class PlayMeditationActivity : BaseActivity() {
val currentPosition = mMediaPlayer?.currentPosition
duration = mMediaPlayer?.duration ?: 0
if (current > 0) {
mMediaPlayer?.seekTo(current * 1000)
seekbar_play_progress.max = duration
seekbar_play_progress.progress = current
exo_position.text = MediaPlayerTimeUtil.calculateTime(current)
......@@ -932,7 +937,7 @@ class PlayMeditationActivity : BaseActivity() {
if (event.mediaUrl == MediaPlayerManager.getInstance(this)?.getAudioPath()) {
return
}
initMediaPlayer(event.mediaUrl, 0)
initMediaPlayer(event.mediaUrl, 0, mMediaIdFromLocal == mMediaId)
}
}
......
......@@ -15,6 +15,14 @@ class MediaPlayerManager private constructor() {
private var mMediaPlayCallBack:MediaPlayCallBack?=null
private var mAudioPaths = mutableListOf<String>()
private var mMediaId:Long? = null
fun setMediaId(mediaId:Long?){
mMediaId = mediaId
}
fun getMediaId():Long? = mMediaId
fun setAudioPath(path: String,isLoop:Boolean = false){
val attrs = AudioAttributes.Builder()
......@@ -56,11 +64,11 @@ class MediaPlayerManager private constructor() {
}
fun stop() {
mMediaPlayer?.reset()
mMediaPlayer?.stop()
}
fun release() {
mMediaPlayer?.reset()
mMediaPlayer?.stop()
}
fun setOnPreparedListener(listener: OnMediaPlayerManagerListener){
......
......@@ -70,10 +70,10 @@ class MeditationWindowService : LifecycleService() {
private var mObservable: Observable<Long>? = null
private var mObserver: Observer<Long>? = null
private var mProgressTimer = Timer()
private lateinit var mSeekBar : AppCompatSeekBar
private var currentMediaId:Long? = null
override fun onCreate() {
super.onCreate()
......@@ -157,6 +157,10 @@ class MeditationWindowService : LifecycleService() {
}
private fun updateFloatView(meditation: MeditationPlayModuleBean.MeditationDetail) {
currentMediaId = meditation.mediaId
MediaPlayerManager.getInstance(this)?.setMediaId(currentMediaId)
mMediaPlayer = MediaPlayerManager.getInstance(this)?.getMediaPlayer()
floatRootView?.setOnClickListener {
//悬浮窗暂停点击事件
......@@ -168,8 +172,6 @@ class MeditationWindowService : LifecycleService() {
intent.putExtra("MEDITATION_TYPE", meditation.meditationType)
intent.putExtra("MEDIA_COVER_URL", meditation.coverImageUrl)
intent.putExtra("MEDIA_URL", meditation.mediaUrl)
intent.putExtra("BROAD_CAST_TIME",
(ivProgress?.curProcess?.div(1000.00))?.roundToInt() ?: 0)
intent.flags = FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
......
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