question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Exoplayer - audio auto focus]

See original GitHub issue

Hello 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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
krocardcommented, Oct 8, 2020

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 switch USAGE_MEDIA for what usage best describe your usage.

0reactions
Samrobbocommented, Oct 8, 2020

You can see #7399 for an explanation into this more, and we currently have #7317 to track the addition of more audio focus modes.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found