Sam
10/02/2020, 10:08 AMThanks
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" />