|
|
@ -10,6 +10,7 @@ import androidx.media.AudioManagerCompat |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
|
|
|
|
object MediaHelp { |
|
|
|
object MediaHelp { |
|
|
|
|
|
|
|
|
|
|
|
const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
|
|
|
const val MEDIA_SESSION_ACTIONS = (PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
|
|
|
or PlaybackStateCompat.ACTION_REWIND |
|
|
|
or PlaybackStateCompat.ACTION_REWIND |
|
|
|
or PlaybackStateCompat.ACTION_PLAY |
|
|
|
or PlaybackStateCompat.ACTION_PLAY |
|
|
@ -32,18 +33,20 @@ object MediaHelp { |
|
|
|
or PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE |
|
|
|
or PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE |
|
|
|
or PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED) |
|
|
|
or PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED) |
|
|
|
|
|
|
|
|
|
|
|
fun getFocusRequest(audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener): AudioFocusRequestCompat { |
|
|
|
fun buildAudioFocusRequestCompat( |
|
|
|
|
|
|
|
audioFocusChangeListener: AudioManager.OnAudioFocusChangeListener |
|
|
|
|
|
|
|
): AudioFocusRequestCompat { |
|
|
|
val mPlaybackAttributes = AudioAttributesCompat.Builder() |
|
|
|
val mPlaybackAttributes = AudioAttributesCompat.Builder() |
|
|
|
.setUsage(AudioAttributesCompat.USAGE_MEDIA) |
|
|
|
.setUsage(AudioAttributesCompat.USAGE_MEDIA) |
|
|
|
.setContentType(AudioAttributesCompat.CONTENT_TYPE_MUSIC) |
|
|
|
.setContentType(AudioAttributesCompat.CONTENT_TYPE_MUSIC) |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
return AudioFocusRequestCompat.Builder(AudioManagerCompat.AUDIOFOCUS_GAIN) |
|
|
|
return AudioFocusRequestCompat.Builder(AudioManagerCompat.AUDIOFOCUS_GAIN) |
|
|
|
.setAudioAttributes(mPlaybackAttributes) |
|
|
|
.setAudioAttributes(mPlaybackAttributes) |
|
|
|
//.setAcceptsDelayedFocusGain(true) |
|
|
|
|
|
|
|
.setOnAudioFocusChangeListener(audioFocusChangeListener) |
|
|
|
.setOnAudioFocusChangeListener(audioFocusChangeListener) |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return 音频焦点 |
|
|
|
* @return 音频焦点 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|