Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

[C-1065][C-1066] Primitive download and playback for tracks offline#2021

Merged
amendelsohn merged 11 commits into
mainfrom
amendel-download-a-file
Sep 29, 2022
Merged

[C-1065][C-1066] Primitive download and playback for tracks offline#2021
amendelsohn merged 11 commits into
mainfrom
amendel-download-a-file

Conversation

@amendelsohn

Copy link
Copy Markdown
Contributor

Description

Checkpoint for offline mode including:

  1. Can manually trigger download of all favorites
  2. Stores mp3, album art, and track json in caches directory that the os allocates for Audius app
  3. If available, playback will select the stored audio file instead of streaming it

Note: This is not production-ready code, and much of this may be refactored as we encounter other concerns with download and playback. Looking for early feedback and concerns.

Known issues:

  1. We aren't yet loading the track json back into state, so even if a track's information is available offline, we won't be able to load and play it back in a subsequent session
  2. There are some debugging methods checked in for convenience
  3. Ran into a couple type errors with existing store state, and didn't want to mess with them without digging deeper

Dragons

Just need to ensure there's no impact to current behavior

How Has This Been Tested?

iOS simulator

Feature Flags

All of these changes are experimental and not ready for consumption.
There should be no UI changes to users without the OFFLINE_MODE_ENABLED feature flag.
The flag is not enabled for any prod users.

@nicoback2 nicoback2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so fire 🔥🔥🔥

Comment thread packages/mobile/src/components/audio/Audio.tsx Outdated
Comment thread packages/mobile/src/hooks/useOfflineTrack.ts Outdated
Comment thread packages/mobile/src/services/offline-downloader/offline-storage.ts Outdated
Comment thread packages/mobile/src/services/offline-downloader/offline-storage.ts Outdated
}

export const getArtFileNameFromUri = (uri: string) => {
return uri.split('/').slice(-1)[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we just named them all the same thing like "Artwork"? (more predictable)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these will be named by the image size like 150x150.jpg

Comment thread packages/mobile/src/services/offline-downloader/offline-storage.ts Outdated
await downloadIfNotExists(coverArtUri, coverArtDirectory, coverArtFileName)
}
await tryDownloadTrackFromEachCreatorNode(track)
await writeTrackJson(track, collection)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we do if either of these steps fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really, we should check if all of the assets exist before writing downloaded_time to the track json. There are more steps that need to happen here, so I haven't gotten to that yet, but it's 100% something we need to worry about. I'll add a todo for the next round.

Comment thread packages/mobile/src/services/offline-downloader/offline-downloader.ts Outdated
Comment thread packages/mobile/src/services/offline-downloader/offline-downloader.ts Outdated

@sliptype sliptype left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work!!!

Comment thread packages/mobile/src/hooks/useOfflineTrack.ts Outdated
Comment thread packages/mobile/src/screens/favorites-screen/FavoritesScreen.tsx Outdated

// Main entrypoint - perform all steps required to complete a download
export const downloadTrack = async (trackId: number, collection: string) => {
const state = store.getState()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we are doing this anywhere else, all this logic feels like it might actually belong in sagas. But I'm pretty anti-saga these days so would love to hear other people's thoughts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It felt weird writing it too. Currently, we usually call this from a component that has the state, but I wanted to keep it reusable for the potential background process. However, we won't be able to use the state their either. Keeping it simple for now, but open to ideas.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in standup. Seems like this is the way for now


const tryDownloadTrackFromEachCreatorNode = async (track: Track) => {
const state = store.getState()
const user = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not already have this in the store?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we probably do. I was teaching myself how to use the API 😅

@amendelsohn amendelsohn Sep 29, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, wait. Not necessarily. If we're downloading all of our favorites we may not have loaded all of them yet. For now, yes, but in the future we will start this process whenever the app is open (and possibly in the background as well). I think I currently have a mix of logic meant to work in the background and logic that doesn't. It's going to need some further separation and cleanup.

Comment thread packages/mobile/src/services/offline-downloader/offline-storage.ts Outdated
Comment thread packages/mobile/src/utils/fileSystem.ts
@amendelsohn amendelsohn merged commit 544b01e into main Sep 29, 2022
@amendelsohn amendelsohn deleted the amendel-download-a-file branch September 29, 2022 23:32
audius-infra pushed a commit that referenced this pull request Oct 1, 2022
[287f114] [C-1179] Fix edit-profile (#2048) Dylan Jeffers
[65456c9] [C-1207] Fix stem downloads (#2041) Dylan Jeffers
[aa7183c] Fix duplicate playlists once playlist is confirmed  / Await feature flag response in sagas C-1199 (#2044) nicoback2
[2340604] [C-1208] Track playback UID is not consistent when clicking into track (#2046) Sebastian Klingler
[b300cba] Add premium content default fields to track upload (#2042) Saliou Diallo
[e80e0bb] [PAY-655] Refactor challenges config, fix bugs (#2016) Michael Piazza
[86d4741] [C-1206] double check before declaring offline state (#2034) Andrew Mendelsohn
[69ccfac] Upgrade sdk 1.0.8 (#2040) Isaac Solo
[3c8ac81] Fix image uploads in new native (#2019) nicoback2
[e0faae7] Fix tracks/reposts lineups for artist with handles with capitials (#2039) Dylan Jeffers
[32b472b] [C-481] Fix profile header loading jank (#2038) Dylan Jeffers
[7e3a4c6] [C-1128] Add profile screen skeleton (#2037) Dylan Jeffers
[e3390af] Improve navigation perf related to drawer context (#2036) Dylan Jeffers
[9a12d48] Fix profile reposts loading issue (#2035) Dylan Jeffers
[544b01e] [C-1065][C-1066] Primitive download and playback for tracks offline (#2021) Andrew Mendelsohn
[d335a31] User entity manager (#2017) Joseph Lee
[522f044] Disable dominant color on mobile (#2031) Sebastian Klingler
[c3093a6] Add AudioTransactionsIcon component (#2030) Kyle Shanks
[c31d1b2] Fix some tests c-1140 (#1966) nicoback2
[575caad] [C-1197] Custom skeleton for feed tip tile (#2027) Raymond Jacobson
[8399ee1] fix new playlist made from track - invalid date (#2029) nicoback2
[3971aaf] [C-1154] Deep linking (#2023) Sebastian Klingler
[fcaf65a] [C-1195] Fix image loading in image hooks (#2025) Dylan Jeffers
[6f54ba1] [C-1194] Fix desktop profile state (#2022) Dylan Jeffers
[3044ded] Fix navigation context scope and setting (#2026) Dylan Jeffers
[4c8bb56] [C-1092] Implement eager load utils in mobile (#2002) Raymond Jacobson
[37048f6] Fix static server crash (#2024) Sebastian Klingler
[4d7bd27] Add entity manager address to dev (#2013) Isaac Solo
[d77ee2d] Fix feeling lucky typecheck (#2020) Isaac Solo
[e83d105] Update feeling lucky to not rely on latest track (#1954) Isaac Solo
[af72734] Add new table for Artist Dashboard (#2018) Kyle Shanks
[f3f8abb] [C-1177] Move tipping requests to api client (#1995) Raymond Jacobson
[b2b986d] [C-1170] Optimistically add/remove reposted tracks/collections (#2009) Dylan Jeffers
[0fda0b8] [PAY-651][PAY-613] Add Stripe Provider to On Ramps (#1950) Marcus Pasell
[5cb01d0] [C-1181] skip connection check if not in foreground (#2010) Andrew Mendelsohn
[254f42e] [C-1157] Fix remix icon position (#2014) Dylan Jeffers
[33b10ee] [C-1164] Fix collections screen loading issues (#2005) Dylan Jeffers
[9c1c1ce] Cast port to number (#2015) Sebastian Klingler
[d656b0a] Upgrade sdk 1.0.6 (#2012) Isaac Solo
[9e5dfef] Fix static server error (#2011) Sebastian Klingler
[42aa891] Hardcode web-sync static-server port (#2008) Dylan Jeffers
[9a106c3] Remove more webview instructions from readme (#2007) Sebastian Klingler
[d68aa89] Omit creator_node_endpoint when updating metadata via collectible fetch (#2006) Sebastian Klingler
[8b16e7f] Use .env.dev instead of .env.dev.local (#2004) Raymond Jacobson
[82864e0] Fix start:dev command (#2003) Raymond Jacobson
[1661b77] [C-1150, C-1165] Fix app-tab navigation (#2001) Dylan Jeffers
[8235eb0] [INF-180] Update client for new compose local dev (#1577) Raymond Jacobson
[71d1e92] [C-1167,C-1171] Fix missing tip data (#2000) Dylan Jeffers
[1c3d609] [C-1156, C-1055, C-1159] Fix profile follow button (#1999) Dylan Jeffers
[2005467] [C-1174] Fix blank listening history screen (#1998) Dylan Jeffers
[42945e3] Remove tmpl env vars (#1997) Raymond Jacobson
[f637ded] [C-1173] Reintegrate WebAppAccountSync (#1996) Dylan Jeffers
[b11f04d] [C-1176] Improve ExploreScreen performance (#1994) Dylan Jeffers
[f6680c5] [C-536] Cache makeStyles StyleSheets (#1993) Dylan Jeffers
@AudiusProject AudiusProject deleted a comment from linear Bot Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants