diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index efe599857..c22ed4784 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -95,10 +95,7 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a override fun observeLiveBus() { observeEvent(Bus.AUDIO_NEXT) { - viewModel.durChapterIndex = viewModel.durChapterIndex + 1 - viewModel.bookData.value?.let { - viewModel.loadContent(it, viewModel.durChapterIndex) - } + viewModel.moveToNext() } observeEvent(Bus.AUDIO_STATE) { status = it diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index b7022cb82..458097f54 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -11,6 +11,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp import io.legado.app.model.WebBook +import io.legado.app.service.help.AudioPlay import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -183,6 +184,19 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) } } + fun moveToNext() { + if (durChapterIndex < chapterSize - 1) { + durChapterIndex++ + bookData.value?.let { + it.durChapterIndex = durChapterIndex + saveRead(it) + loadContent(it, durChapterIndex) + } + } else { + AudioPlay.stop(context) + } + } + fun saveRead(book: Book? = bookData.value) { execute { book?.let { book ->