diff --git a/components/spotify/cspot/include/SpircController.h b/components/spotify/cspot/include/SpircController.h index 32cbd182..a681031b 100644 --- a/components/spotify/cspot/include/SpircController.h +++ b/components/spotify/cspot/include/SpircController.h @@ -37,6 +37,7 @@ class SpircController { private: std::shared_ptr manager; std::string username; + bool firstFrame = true; std::unique_ptr player; std::unique_ptr state; std::shared_ptr audioSink; diff --git a/components/spotify/cspot/src/ChunkedAudioStream.cpp b/components/spotify/cspot/src/ChunkedAudioStream.cpp index 62fe7a0d..432eb103 100644 --- a/components/spotify/cspot/src/ChunkedAudioStream.cpp +++ b/components/spotify/cspot/src/ChunkedAudioStream.cpp @@ -156,7 +156,6 @@ void ChunkedAudioStream::startPlaybackLoop() void ChunkedAudioStream::seek(size_t dpos, Whence whence) { - BELL_LOG(info, "cspot", "%d", dpos); auto seekPos = 0; switch (whence) { diff --git a/components/spotify/cspot/src/ChunkedByteStream.cpp b/components/spotify/cspot/src/ChunkedByteStream.cpp index 643544d3..00140ee6 100644 --- a/components/spotify/cspot/src/ChunkedByteStream.cpp +++ b/components/spotify/cspot/src/ChunkedByteStream.cpp @@ -31,6 +31,7 @@ void ChunkedByteStream::fetchFileInformation() { endChunk->keepInMemory = true; chunks.push_back(endChunk); + requestChunk(0); } std::shared_ptr ChunkedByteStream::getChunkForPosition(size_t position) { @@ -57,11 +58,14 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) { std::scoped_lock lock(this->readMutex); auto chunk = getChunkForPosition(pos); uint16_t chunkIndex = this->pos / AUDIO_CHUNK_SIZE; - for (auto it = chunks.begin(); it != chunks.end();) { - if (((*it)->endPositionstartPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) { - it = chunks.erase(it); - } else { - it++; + + if (loadAheadEnabled) { + for (auto it = chunks.begin(); it != chunks.end();) { + if (((*it)->endPositionstartPosition>(pos + 2 * AUDIO_CHUNK_SIZE)) && !(*it)->keepInMemory) { + it = chunks.erase(it); + } else { + it++; + } } } @@ -85,7 +89,7 @@ size_t ChunkedByteStream::read(uint8_t *buf, size_t nbytes) { pos += read; auto nextChunkPos = ((chunkIndex + 1) * AUDIO_CHUNK_SIZE) + 1; - if (loadAheadEnabled && nextChunkPos + AUDIO_CHUNK_SIZE < fileSize) { + if (loadAheadEnabled && nextChunkPos < fileSize) { auto nextChunk = getChunkForPosition(nextChunkPos); if (nextChunk == nullptr) { @@ -117,7 +121,6 @@ size_t ChunkedByteStream::attemptRead(uint8_t *buffer, size_t bytes, std::shared void ChunkedByteStream::seek(size_t nbytes) { std::scoped_lock lock(this->readMutex); - BELL_LOG(info, "cspot", "seeking to %d", nbytes); pos = nbytes; diff --git a/components/spotify/cspot/src/PlayerState.cpp b/components/spotify/cspot/src/PlayerState.cpp index 70e87430..2b3f9aea 100644 --- a/components/spotify/cspot/src/PlayerState.cpp +++ b/components/spotify/cspot/src/PlayerState.cpp @@ -137,7 +137,7 @@ void PlayerState::updatePositionMs(uint32_t position) void PlayerState::updateTracks() { CSPOT_LOG(info, "---- Track count %d", remoteFrame.state.track_count); - //innerFrame.state.context_uri = remoteFrame.state.context_uri == nullptr ? nullptr : strdup(remoteFrame.state.context_uri); + innerFrame.state.context_uri = remoteFrame.state.context_uri == nullptr ? nullptr : strdup(remoteFrame.state.context_uri); std::copy(std::begin(remoteFrame.state.track), std::end(remoteFrame.state.track), std::begin(innerFrame.state.track)); innerFrame.state.track_count = remoteFrame.state.track_count; innerFrame.state.has_playing_track_index = true; diff --git a/components/spotify/cspot/src/SpircController.cpp b/components/spotify/cspot/src/SpircController.cpp index da9586aa..4f7e0264 100644 --- a/components/spotify/cspot/src/SpircController.cpp +++ b/components/spotify/cspot/src/SpircController.cpp @@ -103,7 +103,6 @@ void SpircController::prevSong() { } void SpircController::handleFrame(std::vector &data) { - //pb_release(Frame_fields, &state->remoteFrame); pbDecode(state->remoteFrame, Frame_fields, data); switch (state->remoteFrame.typ) {