feelfreelinux / cspot

A Spotify Connect player targeting, but not limited to embedded devices (ESP32).
Other
479 stars 44 forks source link

fix podcast won't play #160

Closed philippe44 closed 12 months ago

philippe44 commented 1 year ago

There is a string search for "episode" at the beginning of track's URI. I added something a while ago for compiler that are not "fully" C++20 and don't have start_with method. But it seems that the URI is now spotify::episode:.

So I just did a general search for episode: instead of forcing it to start with it. Feel free to change it to something different, I don't know what the URI should exactly be (but a regex maybe an issue due to what regex drains with in term of C++ code)

[edit]: I've also added another fix when user pressed "PREV" already on 1st track. The state machine was getting lost, pausing the player and ending in a dead lock. I've also added the usual behavior that if we are more than 3 sec in a track, we restart it instead of going to previous. I'm not sure if we should use innerframe or remoteframe or if this matter in that case.

I've also fixed what happens when pressing NEXT and PREV on last track (or when NEXT track fails). Probably complicated to explain, but the previous logic pausing and resuming to 0 did not work. The logic now is simply abort and reload current track when NEXT fails for any reason. Previously:

I've also removed some redundant calls in skipTrack because I think that now TrackPlayer does the job of sending PLAY/PAUSE, changing inner status and notify(), so there is no reason to do it in skipTrack which is much more simple.

It's a bit more code changes that I'd like but it's not behavior changes for normal playback. I think stopping on a failed skip event but being able to press "PLAY" and restart the current track is the expected behavior. You could still send the NEXT/PREV event even in case of failure, but I'm not sure I see the point anymore as "PLAYBACK_START" will be sent which causes the player to reset.

Note that I've changed the cli example a bit because I think that for consistency, PLAYBACK_START event should not start playback, but only be in pause mode and wait for PLAY event.

With these changes, one can argue that "FLUSH" event (that I think I introduced a while ago) is now un-needed as it is only used in "replace frame"

Last but not least, at the end of a playlist, there was no method to end properly, instruct Spotify that we are done and be ready to play again by simply pressing PLAY. I've added spirc::notifyAudioEnded() which nicely use the new resetState to do all that.