From bd599d6ca9b4198a6cc06f3414c97a101772a643 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 13 Nov 2020 11:47:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/AudioPlayService.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 9fb514430..340395096 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -282,10 +282,12 @@ class AudioPlayService : BaseService(), } } - private fun loadContent(chapter: BookChapter) = AudioPlay.apply { - book?.let { book -> - webBook?.getContent(book, chapter, scope = this@AudioPlayService) - ?.onSuccess { content -> + private fun loadContent(chapter: BookChapter) { + val book = AudioPlay.book + val webBook = AudioPlay.webBook + if (book != null && webBook != null) { + webBook.getContent(book, chapter, scope = this@AudioPlayService) + .onSuccess { content -> removeLoading(chapter.index) if (content.isEmpty()) { withContext(Main) { @@ -294,10 +296,12 @@ class AudioPlayService : BaseService(), } else { contentLoadFinish(chapter, content) } - }?.onError { + }.onError { contentLoadFinish(chapter, it.localizedMessage ?: toString()) removeLoading(chapter.index) } + } else { + toast("book or source is null") } }