From d354c2b3cc547e409c2dd8b3a2dd3ad98ca19380 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 9 Sep 2022 18:14:23 +0200 Subject: [PATCH] pause when unplugging headphones --- .../com/github/libretube/activities/OfflinePlayerActivity.kt | 1 + .../main/java/com/github/libretube/fragments/PlayerFragment.kt | 1 + .../main/java/com/github/libretube/services/BackgroundMode.kt | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/activities/OfflinePlayerActivity.kt b/app/src/main/java/com/github/libretube/activities/OfflinePlayerActivity.kt index 3178cf738..1d00a3378 100644 --- a/app/src/main/java/com/github/libretube/activities/OfflinePlayerActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/OfflinePlayerActivity.kt @@ -46,6 +46,7 @@ class OfflinePlayerActivity : BaseActivity() { private fun initializePlayer() { player = ExoPlayer.Builder(this) + .setHandleAudioBecomingNoisy(true) .build() playerView = binding.player diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index d3e099a61..794c9809d 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -1315,6 +1315,7 @@ class PlayerFragment : BaseFragment() { .setMediaSourceFactory(DefaultMediaSourceFactory(dataSourceFactory)) .setLoadControl(loadControl) .setTrackSelector(trackSelector) + .setHandleAudioBecomingNoisy(true) .build() exoPlayer.setAudioAttributes(audioAttributes, true) diff --git a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt index 14b4ea40a..c48d59a78 100644 --- a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt @@ -190,9 +190,10 @@ class BackgroundMode : Service() { audioAttributes = AudioAttributes.Builder() .setUsage(C.USAGE_MEDIA) - .setContentType(C.CONTENT_TYPE_MUSIC) + .setContentType(C.AUDIO_CONTENT_TYPE_MUSIC) .build() player = ExoPlayer.Builder(this) + .setHandleAudioBecomingNoisy(true) .setAudioAttributes(audioAttributes, true) .build()