[Exoplayer - audio auto focus] Hello everyone, I ...
# android
s
[Exoplayer - audio auto focus] Hello everyone, I have problem with Audio focus on Exoplayer 2.9.2 => My expectation : 1. When my app is playing video -> pause Spotify 2. 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
Copy code
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" />