Skip to content

feat: add support for local file playback#332

Merged
jpochyla merged 2 commits intojpochyla:masterfrom
superhawk610:feat/local-file-playback
Sep 22, 2022
Merged

feat: add support for local file playback#332
jpochyla merged 2 commits intojpochyla:masterfrom
superhawk610:feat/local-file-playback

Conversation

@superhawk610
Copy link
Copy Markdown
Contributor

@superhawk610 superhawk610 commented Aug 26, 2022

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 of

  • item_id a unique, opaque identifier, meaningful only to Spotify's API
  • file_id a unique identifier that points into the local filesystem cache
  • file_format an enum indicating what codec this file should be played with
  • duration a std::time::Duration indicating the track's length

For remote files hosted on CDN, Spotify's API provides item_id, file_format, and duration, and the app stores file_id if/when it begins streaming the track. For local files, we don't need file_id, since the track already resides on disk, so it's left blank (Default::default()). We're able to guess file_format and duration by using Symphonia's Probe. Local files don't have an item_id on Spotify's end, so we have to generate our own. To do this, this PR includes LocalItemRegistry, which is a singleton that registers PathBufs 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).

@jpochyla jpochyla force-pushed the feat/local-file-playback branch from 44fd7f5 to 72d3a3b Compare September 22, 2022 23:28
@jpochyla jpochyla merged commit 0b5b6ce into jpochyla:master Sep 22, 2022
@jpochyla
Copy link
Copy Markdown
Owner

Thanks a lot, and sorry for the long wait :( I've changed some nits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playback of local files

2 participants