mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
97bae57675
commit
fc84a5b9b2
@ -10,6 +10,7 @@ import androidx.media.AudioManagerCompat
|
||||
import io.legado.app.R
|
||||
|
||||
object MediaHelp {
|
||||
|
||||
const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
|
||||
or PlaybackStateCompat.ACTION_REWIND
|
||||
or PlaybackStateCompat.ACTION_PLAY
|
||||
@ -32,18 +33,20 @@ object MediaHelp {
|
||||
or PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
|
||||
or PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED)
|
||||
|
||||
fun getFocusRequest(audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener): AudioFocusRequestCompat {
|
||||
fun buildAudioFocusRequestCompat(
|
||||
audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener
|
||||
): AudioFocusRequestCompat {
|
||||
val mPlaybackAttributes = AudioAttributesCompat.Builder()
|
||||
.setUsage(AudioAttributesCompat.USAGE_MEDIA)
|
||||
.setContentType(AudioAttributesCompat.CONTENT_TYPE_MUSIC)
|
||||
.build()
|
||||
return AudioFocusRequestCompat.Builder(AudioManagerCompat.AUDIOFOCUS_GAIN)
|
||||
.setAudioAttributes(mPlaybackAttributes)
|
||||
//.setAcceptsDelayedFocusGain(true)
|
||||
.setOnAudioFocusChangeListener(audioFocusChangeListener)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 音频焦点
|
||||
*/
|
||||
|
@ -62,7 +62,7 @@ class AudioPlayService : BaseService(),
|
||||
}
|
||||
|
||||
private val mFocusRequest: AudioFocusRequestCompat by lazy {
|
||||
MediaHelp.getFocusRequest(this)
|
||||
MediaHelp.buildAudioFocusRequestCompat(this)
|
||||
}
|
||||
private val exoPlayer: ExoPlayer by lazy {
|
||||
ExoPlayer.Builder(this).setLoadControl(
|
||||
|
@ -56,7 +56,7 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
}
|
||||
|
||||
private val mFocusRequest: AudioFocusRequestCompat by lazy {
|
||||
MediaHelp.getFocusRequest(this)
|
||||
MediaHelp.buildAudioFocusRequestCompat(this)
|
||||
}
|
||||
private val mediaSessionCompat: MediaSessionCompat by lazy {
|
||||
MediaSessionCompat(this, "readAloud")
|
||||
|
Loading…
Reference in New Issue
Block a user