pull/61/head^2
kunfei 5 years ago
parent 4f7a4dc1e7
commit a53017be90
  1. 15
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  2. 8
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  3. 12
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  4. 5
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt

@ -45,10 +45,10 @@ class AudioPlayService : BaseService(),
companion object { companion object {
var isRun = false var isRun = false
var pause = false
var timeMinute: Int = 0 var timeMinute: Int = 0
} }
var pause = false
private val handler = Handler() private val handler = Handler()
private lateinit var audioManager: AudioManager private lateinit var audioManager: AudioManager
private var mFocusRequest: AudioFocusRequest? = null private var mFocusRequest: AudioFocusRequest? = null
@ -92,7 +92,6 @@ class AudioPlayService : BaseService(),
Action.prev -> moveToPrev() Action.prev -> moveToPrev()
Action.next -> moveToNext() Action.next -> moveToNext()
Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f))
Action.moveTo -> moveTo(intent.getIntExtra("index", AudioPlay.durChapterIndex))
Action.addTimer -> addTimer() Action.addTimer -> addTimer()
Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) Action.setTimer -> setTimer(intent.getIntExtra("minute", 0))
Action.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) Action.adjustProgress -> adjustProgress(intent.getIntExtra("position", position))
@ -135,7 +134,7 @@ class AudioPlayService : BaseService(),
} }
private fun pause(pause: Boolean) { private fun pause(pause: Boolean) {
this.pause = pause AudioPlayService.pause = pause
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
position = mediaPlayer.currentPosition position = mediaPlayer.currentPosition
mediaPlayer.pause() mediaPlayer.pause()
@ -313,16 +312,6 @@ class AudioPlayService : BaseService(),
} }
} }
private fun moveTo(index: Int) {
mediaPlayer.pause()
AudioPlay.durChapterIndex = index
AudioPlay.durPageIndex = 0
AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex
saveRead()
position = 0
loadContent(AudioPlay.durChapterIndex)
}
private fun moveToPrev() { private fun moveToPrev() {
if (AudioPlay.durChapterIndex > 0) { if (AudioPlay.durChapterIndex > 0) {
mediaPlayer.pause() mediaPlayer.pause()

@ -89,12 +89,4 @@ object AudioPlay {
} }
} }
fun moveTo(context: Context, index: Int) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.moveTo
intent.putExtra("index", index)
context.startService(intent)
}
}
} }

@ -22,6 +22,7 @@ import io.legado.app.help.ImageLoader
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.dialogs.okButton
import io.legado.app.service.AudioPlayService
import io.legado.app.service.help.AudioPlay import io.legado.app.service.help.AudioPlay
import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.chapterlist.ChapterListActivity
@ -172,7 +173,16 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
when (requestCode) { when (requestCode) {
requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let { requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let {
if (it != AudioPlay.durChapterIndex) { if (it != AudioPlay.durChapterIndex) {
AudioPlay.moveTo(this, it) val isPlay = !AudioPlayService.pause
AudioPlay.pause(this)
AudioPlay.status = Status.STOP
AudioPlay.durChapterIndex = it
AudioPlay.durPageIndex = 0
AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex
viewModel.saveRead()
if (isPlay) {
AudioPlay.play(this)
}
} }
} }
} }

@ -124,13 +124,16 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
} }
} }
private fun saveRead() { fun saveRead() {
execute { execute {
AudioPlay.book?.let { book -> AudioPlay.book?.let { book ->
book.lastCheckCount = 0 book.lastCheckCount = 0
book.durChapterTime = System.currentTimeMillis() book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = AudioPlay.durChapterIndex book.durChapterIndex = AudioPlay.durChapterIndex
book.durChapterPos = AudioPlay.durPageIndex book.durChapterPos = AudioPlay.durPageIndex
App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let {
book.durChapterTitle = it.title
}
App.db.bookDao().update(book) App.db.bookDao().update(book)
} }
} }

Loading…
Cancel
Save