Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setArtworkUri could accept file:// and content:// Uris #271

Open
y20k opened this issue Mar 15, 2023 · 3 comments
Open

setArtworkUri could accept file:// and content:// Uris #271

y20k opened this issue Mar 15, 2023 · 3 comments
Assignees

Comments

@y20k
Copy link

y20k commented Mar 15, 2023

Use case description

I develop and maintain an audio app that stores the covers for its media as files locally (in external storage). I want to use those local files as the artwork in a MediaItem.

Proposed solution

setArtworkUri in MediaMetadata.Builder could accept Uris with the scheme file:// and content://

Alternatives considered

(1) I can convert the local cover file into a ByteArray and pass that to setArtworkData. But that solution uses more memory compared to just setting that artwork Uri.
(2) setArtworkUri somewhat works with file://-Uris ... in the sense that the correct cover is displayed in the app's Notification. But MediaDataManager throws a FileNotFoundException (Permission denied). So I guess other clients of my app will not be able to see the cover.

@marcbaechinger
Copy link
Contributor

Thanks!

We recently added DataSourceBitmapLoader that is able to download from content:// URIs. I think this should work with file:// URIs as well.

For proper integration we should:

  1. Use DataSourceBitmapLoader in the demo app to test and showcase it in use.
  2. In addition we should investigate whether we can just send artworkUris with schemes content:// and file:// to the legacy media session without downloading and converting the bitmap. The reason for this is that content:// and file:// are directly supported by SystemUI and we can avoid sending byte arrays over the binder.

@marcbaechinger
Copy link
Contributor

But MediaDataManager throws a FileNotFoundException (Permission denied). So I guess other clients of my app will not be able to see the cover.

For sharing with other apps you probably need to use a content://. The other app can then use a DataSourceBitmapLoader to download the bitmap from the content URI.

@y20k
Copy link
Author

y20k commented Mar 16, 2023

Hi @marcbaechinger

Thank you. I will try out DataSourceBitmapLoader when it becomes available - in the next RC release I presume. That sounds like very good solution. And if in the future setArtworkUri will automagically be able to fetch artwork from local Uris, that would be great (and in my opinion intuitive). But as long as the problem can be solved by using DataSourceBitmapLoader, that totally fine, too.

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

No branches or pull requests

2 participants