diff --git a/app/src/main/java/io/legado/app/help/MediaHelp.kt b/app/src/main/java/io/legado/app/help/MediaHelp.kt new file mode 100644 index 000000000..377fd5fbd --- /dev/null +++ b/app/src/main/java/io/legado/app/help/MediaHelp.kt @@ -0,0 +1,20 @@ +package io.legado.app.help + +import android.content.Context +import android.media.MediaPlayer +import io.legado.app.R + +object MediaHelp { + + + fun playSilentSound(mContext: Context) { + try { + // Stupid Android 8 "Oreo" hack to make media buttons work + val mMediaPlayer = MediaPlayer.create(mContext, R.raw.silent_sound) + mMediaPlayer.setOnCompletionListener { it.release() } + mMediaPlayer.start() + } catch (ignored: Exception) { + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index bc798a77b..bd48eefed 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -17,6 +17,7 @@ import io.legado.app.base.BaseService import io.legado.app.constant.AppConst import io.legado.app.constant.Bus import io.legado.app.constant.Status +import io.legado.app.help.MediaHelp import io.legado.app.help.PendingIntentHelp import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.utils.postEvent @@ -206,6 +207,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage * @return 音频焦点 */ private fun requestFocus(): Boolean { + MediaHelp.playSilentSound(this) val request: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { audioManager.requestAudioFocus(mFocusRequest) } else { diff --git a/app/src/main/res/raw/silent_sound.mp3 b/app/src/main/res/raw/silent_sound.mp3 new file mode 100644 index 000000000..ce236a279 Binary files /dev/null and b/app/src/main/res/raw/silent_sound.mp3 differ