pull/32/head
kunfei 5 years ago
parent b3ea9f420b
commit 8975e23e19
  1. 7
      app/src/main/java/io/legado/app/help/MediaHelp.kt
  2. 14
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -19,7 +19,6 @@ object MediaHelp {
or PlaybackStateCompat.ACTION_STOP or PlaybackStateCompat.ACTION_STOP
or PlaybackStateCompat.ACTION_SEEK_TO) or PlaybackStateCompat.ACTION_SEEK_TO)
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
fun getFocusRequest(audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener): AudioFocusRequest { fun getFocusRequest(audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener): AudioFocusRequest {
val mPlaybackAttributes = AudioAttributes.Builder() val mPlaybackAttributes = AudioAttributes.Builder()
@ -34,13 +33,11 @@ object MediaHelp {
} }
fun playSilentSound(mContext: Context) { fun playSilentSound(mContext: Context) {
try { kotlin.runCatching {
// Stupid Android 8 "Oreo" hack to make media buttons work // Stupid Android 8 "Oreo" hack to make media buttons work
val mMediaPlayer = MediaPlayer.create(mContext, R.raw.silent_sound) val mMediaPlayer = MediaPlayer.create(mContext, R.raw.silent_sound)
mMediaPlayer.setOnCompletionListener { it.release() } mMediaPlayer.setOnCompletionListener { mMediaPlayer.release() }
mMediaPlayer.start() mMediaPlayer.start()
} catch (ignored: Exception) {
} }
} }
} }

@ -169,11 +169,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
this.pageFactory = factory this.pageFactory = factory
//可做成异步回调 //可做成异步回调
pageFactory?.let { upContent()
prevPage?.setContent(it.previousPage())
curPage?.setContent(it.currentPage())
nextPage?.setContent(it.nextPage())
}
} }
override fun hasNext(): Boolean { override fun hasNext(): Boolean {
@ -185,10 +181,10 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
} }
fun upContent() { fun upContent() {
callback?.let { pageFactory?.let {
it.textChapter()?.let { textChapter -> prevPage?.setContent(it.previousPage())
curPage?.setContent(textChapter.page(it.durChapterIndex())) curPage?.setContent(it.currentPage())
} nextPage?.setContent(it.nextPage())
} }
} }

Loading…
Cancel
Save