From 969ceb4ea70c917e16aedeb71080eba293710f55 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Thu, 16 Mar 2023 20:20:10 -0600 Subject: [PATCH] playback: broadcast audiofx session on play/pause Broadcast the audiofx session when playing/pausing rather than starting and stopping. This is apparently the more correct way to do this. Resolves #391. --- CHANGELOG.md | 13 +++++--- .../auxio/playback/system/PlaybackService.kt | 33 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f73b305..fa9168f3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,18 @@ ## dev -#### What's Fixed -- Fixed MP4-AAC files not playing due to an accidental audio extractor -deletion -- Fix "format" not appearing in song properties view - #### What's Improved - Accept `REPLAYGAIN_*` adjustment information on OPUS files alongside `R128_*` adjustments. - List updates are now consistent across the app +- Search view now trims search queries +- Audio effect (equalizer) session is now broadcast when playing/pausing +rather than on start/stop. + +#### What's Fixed +- Fixed MP4-AAC files not playing due to an accidental audio extractor +deletion +- Fix "format" not appearing in song properties view ## 3.0.3 diff --git a/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt b/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt index 201ad6abf..527f5fed0 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/system/PlaybackService.kt @@ -226,11 +226,7 @@ class PlaybackService : // No song, stop playback and foreground state. logD("Nothing playing, stopping playback") player.stop() - if (openAudioEffectSession) { - // Make sure to close the audio session when we stop playback. - broadcastAudioEffectAction(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION) - openAudioEffectSession = false - } + stopAndSave() return } @@ -238,15 +234,6 @@ class PlaybackService : logD("Loading ${song.rawName}") player.setMediaItem(MediaItem.fromUri(song.uri)) player.prepare() - - if (!openAudioEffectSession) { - // Android does not like it if you start an audio effect session without having - // something within your player buffer. Make sure we only start one when we load - // a song. - broadcastAudioEffectAction(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION) - openAudioEffectSession = true - } - player.playWhenReady = play } @@ -263,9 +250,21 @@ class PlaybackService : override fun onEvents(player: Player, events: Player.Events) { super.onEvents(player, events) - if (events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED) && player.playWhenReady) { - // Mark that we have started playing so that the notification can now be posted. - hasPlayed = true + if (events.contains(Player.EVENT_PLAY_WHEN_READY_CHANGED)) { + if (player.playWhenReady) { + // Mark that we have started playing so that the notification can now be posted. + hasPlayed = true + if (!openAudioEffectSession) { + // Convention to start an audioeffect session on play/pause rather than + // start/stop + broadcastAudioEffectAction(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION) + openAudioEffectSession = true + } + } else if (openAudioEffectSession) { + // Make sure to close the audio session when we stop playback. + broadcastAudioEffectAction(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION) + openAudioEffectSession = false + } } // Any change to the analogous isPlaying, isAdvancing, or positionMs values require