pause when unplugging headphones

This commit is contained in:
Bnyro 2022-09-09 18:14:23 +02:00
parent 147d2151a0
commit d354c2b3cc
3 changed files with 4 additions and 1 deletions

View File

@ -46,6 +46,7 @@ class OfflinePlayerActivity : BaseActivity() {
private fun initializePlayer() {
player = ExoPlayer.Builder(this)
.setHandleAudioBecomingNoisy(true)
.build()
playerView = binding.player

View File

@ -1315,6 +1315,7 @@ class PlayerFragment : BaseFragment() {
.setMediaSourceFactory(DefaultMediaSourceFactory(dataSourceFactory))
.setLoadControl(loadControl)
.setTrackSelector(trackSelector)
.setHandleAudioBecomingNoisy(true)
.build()
exoPlayer.setAudioAttributes(audioAttributes, true)

View File

@ -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()