From 8594d6326423ca058dafb5fb4b94550dee7a73cc Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 4 Nov 2019 20:18:26 +0800 Subject: [PATCH] up --- .../io/legado/app/service/AudioPlayService.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 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 0ecb3571b..082804095 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -25,6 +25,8 @@ import io.legado.app.help.MediaHelp import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.utils.postEvent +import kotlinx.coroutines.launch +import org.jetbrains.anko.toast class AudioPlayService : BaseService(), @@ -99,10 +101,16 @@ class AudioPlayService : BaseService(), private fun play(url: String) { if (requestFocus()) { - postEvent(Bus.AUDIO_STATE, Status.PLAY) - mediaPlayer.reset() - mediaPlayer.setDataSource(url) - mediaPlayer.prepareAsync() + try { + postEvent(Bus.AUDIO_STATE, Status.PLAY) + mediaPlayer.reset() + mediaPlayer.setDataSource(url) + mediaPlayer.prepareAsync() + } catch (e: Exception) { + launch { + toast(e.localizedMessage + " " + url) + } + } } }