[Exoplayer - audio auto focus]
See original GitHub issueHello everyone, I have problem with Audio focus on Exoplayer 2.9.2 => My expectation : When my app is playing video -> pause Spotify When my app is pause/stop/destroy video -> resume Spotify But I have no idea about this, only stop spotify not pause when my app is playing video Thanks
https://medium.com/google-exoplayer/easy-audio-focus-with-exoplayer-a2dcbbe4640e
binding.playerView.setControlDispatcher(object : DefaultControlDispatcher() {
override fun dispatchSetPlayWhenReady(
player: Player?,
playWhenReady: Boolean
): Boolean {
player?.audioComponent?.setAudioAttributes(AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.CONTENT_TYPE_SPEECH)
.build(),true)
binding.playerView.keepScreenOn = playWhenReady
Hawk.put(FEED_VIDEO_AUTO_PLAY, playWhenReady)
setVideoPlayLargest()
return super.dispatchSetPlayWhenReady(player, playWhenReady)
}
})
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:controller_layout_id="@layout/video_tab_playback_control"
app:resize_mode="fixed_width"
app:surface_type="texture_view"
app:use_controller="true" />
```
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Easy Audio Focus with ExoPlayer - Medium
Managing audio focus is a vital part of being a good citizen in the Android ecosystem. Learn how ExoPlayer just made this much...
Read more >Android - SimpleExoPlayer with audio focus - Stack Overflow
You can manage your audio focus with ease in exo player by using setAudioArttribute . Here is the code:
Read more >Manage audio focus - Android Developers
Existing audio focus behaviors. Audio focus in Android 8.0 through Android 11. Automatic ducking; Delayed focus gain. Audio focus in Android ...
Read more >Managing audio focus of two instances of Exoplayer - Reddit
Hello, I'm using the media2 + exoplayer in my application, but facing problems to manage audio focus between two instances of the player....
Read more >Providing Audio Playback for Auto - Android Developers
Devbytes: Android Auto Audio Drivers want to access their music and other audio content on ... see Media Playback, Managing Audio Playback, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
First, if if what your app is playing is long duration (eg music), you should keep the current behaviour. Spotify and playbacks in general are only expected to resume after the playback of a notification or a short priority sound in general.
Now if your app is indeed playing a short sound, for Spotify or any other playback (eg Youtube) to resume after your app has stopped playback, Audio focus transient needs to be requested.
As you are using SimpleExoPlayer’s AudioFocus management, a TRANSIENT audio focus request will be automatically used for usages such as
USAGE_ALARM
(pause),USAGE_NOTIFICATION
(duck). Thus switchUSAGE_MEDIA
for what usage best describe your usage.You can see #7399 for an explanation into this more, and we currently have #7317 to track the addition of more audio focus modes.