From a9ca4c445051b83235387dabd68172e12a57460c Mon Sep 17 00:00:00 2001 From: philippe44 Date: Mon, 13 Nov 2023 22:30:45 -0800 Subject: [PATCH] attempt to fix cspot track issues - release --- components/services/services.c | 2 +- components/spotify/cspot/src/SpircHandler.cpp | 2 +- components/spotify/cspot/src/TrackQueue.cpp | 33 ++++++++----------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/components/services/services.c b/components/services/services.c index ae654ad85..ef6555aec 100644 --- a/components/services/services.c +++ b/components/services/services.c @@ -361,7 +361,7 @@ void services_init(void) { } #endif - // set potential power GPIO on chip first in case expanders are power using these + // set potential power GPIO on chip first in case expanders are powered using these parse_set_GPIO(set_chip_power_gpio); // shared I2C bus diff --git a/components/spotify/cspot/src/SpircHandler.cpp b/components/spotify/cspot/src/SpircHandler.cpp index 92531a641..cdf8f7361 100644 --- a/components/spotify/cspot/src/SpircHandler.cpp +++ b/components/spotify/cspot/src/SpircHandler.cpp @@ -201,7 +201,7 @@ void SpircHandler::handleFrame(std::vector& data) { break; } case MessageType_kMessageTypeReplace: { - CSPOT_LOG(debug, "Got replace frame"); + CSPOT_LOG(debug, "Got replace frame %d", playbackState->remoteTracks.size()); playbackState->syncWithRemote(); // 1st track is the current one, but update the position diff --git a/components/spotify/cspot/src/TrackQueue.cpp b/components/spotify/cspot/src/TrackQueue.cpp index 5c416bbe3..d35d94ef3 100644 --- a/components/spotify/cspot/src/TrackQueue.cpp +++ b/components/spotify/cspot/src/TrackQueue.cpp @@ -591,15 +591,14 @@ bool TrackQueue::updateTracks(uint32_t requestedPosition, bool initial) { std::scoped_lock lock(tracksMutex); bool cleared = true; + // Copy requested track list + currentTracks = playbackState->remoteTracks; + currentTracksIndex = playbackState->innerFrame.state.playing_track_index; + if (initial) { // Clear preloaded tracks preloadedTracks.clear(); - // Copy requested track list - currentTracks = playbackState->remoteTracks; - - currentTracksIndex = playbackState->innerFrame.state.playing_track_index; - if (currentTracksIndex < currentTracks.size()) { // Push a song on the preloaded queue queueNextTrack(0, requestedPosition); @@ -609,28 +608,24 @@ bool TrackQueue::updateTracks(uint32_t requestedPosition, bool initial) { notifyPending = true; playableSemaphore->give(); - } else { - // Copy requested track list - currentTracks = playbackState->remoteTracks; - - // try to not re-load track if we are still loading it - if (preloadedTracks[0]->loading) { + } else if (preloadedTracks[0]->loading) { + // try to not re-load track if we are still loading it + // remove everything except first track preloadedTracks.erase(preloadedTracks.begin() + 1, preloadedTracks.end()); // Push a song on the preloaded queue - CSPOT_LOG(info, "Keeping current track"); + CSPOT_LOG(info, "Keeping current track %d", currentTracksIndex); queueNextTrack(1); cleared = false; - } else { - // Clear preloaded tracks - preloadedTracks.clear(); + } else { + // Clear preloaded tracks + preloadedTracks.clear(); - // Push a song on the preloaded queue - CSPOT_LOG(info, "Re-loading current track"); - queueNextTrack(0, requestedPosition); - } + // Push a song on the preloaded queue + CSPOT_LOG(info, "Re-loading current track"); + queueNextTrack(0, requestedPosition); } return cleared;