From 863fe96ba587c5eb5276f2fdcd04783ef6518b57 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 7 Nov 2019 18:18:05 +0800 Subject: [PATCH] up --- .../java/io/legado/app/service/AudioPlayService.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index a79adb6e4..d03c0296a 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -50,6 +50,7 @@ class AudioPlayService : BaseService(), private val mediaPlayer = MediaPlayer() private var mediaSessionCompat: MediaSessionCompat? = null private var broadcastReceiver: BroadcastReceiver? = null + private var url: String = "" private var position = 0 private val dsRunnable: Runnable = Runnable { doDs() } private var mpRunnable: Runnable = Runnable { upPlayProgress() } @@ -75,7 +76,8 @@ class AudioPlayService : BaseService(), title = intent.getStringExtra("title") ?: "" subtitle = intent.getStringExtra("subtitle") ?: "" position = intent.getIntExtra("position", 0) - play(intent.getStringExtra("url")) + url = intent.getStringExtra("url") + play() } Action.pause -> pause(true) Action.resume -> resume() @@ -100,7 +102,7 @@ class AudioPlayService : BaseService(), postEvent(Bus.AUDIO_STATE, Status.STOP) } - private fun play(url: String) { + private fun play() { upNotification() if (requestFocus()) { try { @@ -147,6 +149,9 @@ class AudioPlayService : BaseService(), } } + /** + * 加载完成 + */ override fun onPrepared(mp: MediaPlayer?) { if (pause) return mp?.start() @@ -167,6 +172,9 @@ class AudioPlayService : BaseService(), return true } + /** + * 播放结束 + */ override fun onCompletion(mp: MediaPlayer?) { handler.removeCallbacks(mpRunnable) postEvent(Bus.AUDIO_NEXT, 1)