From 3117ea253e08b85b81723be3ba7e03b7d9b8082c Mon Sep 17 00:00:00 2001 From: vfsfitvnm Date: Fri, 26 Aug 2022 19:37:58 +0200 Subject: [PATCH] Try fix #241 --- .../vimusic/service/PlayerService.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt index 6641cd5..dd2223c 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt @@ -14,11 +14,13 @@ import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.Color import android.media.MediaMetadata +import android.media.audiofx.AudioEffect import android.media.session.MediaSession import android.media.session.PlaybackState import android.net.Uri import android.os.Build import android.os.Handler +import android.util.Log import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue @@ -169,7 +171,8 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene isPersistentQueueEnabled = preferences.getBoolean(persistentQueueKey, false) isVolumeNormalizationEnabled = preferences.getBoolean(volumeNormalizationKey, false) isInvincibilityEnabled = preferences.getBoolean(isInvincibilityEnabledKey, false) - isShowingThumbnailInLockscreen = preferences.getBoolean(isShowingThumbnailInLockscreenKey, true) + isShowingThumbnailInLockscreen = + preferences.getBoolean(isShowingThumbnailInLockscreenKey, true) val cacheEvictor = when (val size = preferences.getEnum(exoPlayerDiskCacheMaxSizeKey, ExoPlayerDiskCacheMaxSize.`2GB`)) { @@ -375,6 +378,24 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene mediaSession.setMetadata(metadataBuilder.build()) } + private fun sendOpenEqualizerIntent() { + sendBroadcast( + Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION).apply { + putExtra(AudioEffect.EXTRA_AUDIO_SESSION, player.audioSessionId) + putExtra(AudioEffect.EXTRA_PACKAGE_NAME, packageName) + putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC) + } + ) + } + + private fun sendCloseEqualizerIntent() { + sendBroadcast( + Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION).apply { + putExtra(AudioEffect.EXTRA_AUDIO_SESSION, player.audioSessionId) + } + ) + } + private val Player.androidPlaybackState: Int get() = when (playbackState) { Player.STATE_BUFFERING -> if (playWhenReady) PlaybackState.STATE_BUFFERING else PlaybackState.STATE_PAUSED @@ -434,11 +455,13 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene startForegroundService(this@PlayerService, intent()) startForeground(NotificationId, notification()) makeInvincible(false) + sendOpenEqualizerIntent() } else { if (!player.shouldBePlaying) { isNotificationStarted = false stopForeground(false) makeInvincible(true) + sendCloseEqualizerIntent() } notificationManager?.notify(NotificationId, notification) }