feat: add support for local file playback#332
Merged
jpochyla merged 2 commits intojpochyla:masterfrom Sep 22, 2022
Merged
Conversation
44fd7f5 to
72d3a3b
Compare
Owner
|
Thanks a lot, and sorry for the long wait :( I've changed some nits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for local file playback. Local files have been visible in the UI, but not playable, since #136.
Resolves #326.
Implementation
The primary struct used to identify a track for playback is
MediaPath, which is composed ofitem_ida unique, opaque identifier, meaningful only to Spotify's APIfile_ida unique identifier that points into the local filesystem cachefile_formatan enum indicating what codec this file should be played withdurationastd::time::Durationindicating the track's lengthFor remote files hosted on CDN, Spotify's API provides
item_id,file_format, andduration, and the app storesfile_idif/when it begins streaming the track. For local files, we don't needfile_id, since the track already resides on disk, so it's left blank (Default::default()). We're able to guessfile_formatanddurationby using Symphonia'sProbe. Local files don't have anitem_idon Spotify's end, so we have to generate our own. To do this, this PR includesLocalItemRegistry, which is a singleton that registersPathBufs corresponding to local tracks and associates each with a unique ID that may be used in place of Spotify's item ID.I can confirm that this works locally, though actually getting Symphonia to playback all tracks is a bit hit or miss (using an album from Bandcamp, about half the tracks work flawlessly and the other half won't play).