Skip to content

Add setFallbackArt to specify default art - #992

Draft
nt4f04uNd wants to merge 1 commit into
ryanheise:minorfrom
nt4f04uNd:feature/default-album-art
Draft

Add setFallbackArt to specify default art#992
nt4f04uNd wants to merge 1 commit into
ryanheise:minorfrom
nt4f04uNd:feature/default-album-art

Conversation

@nt4f04uNd

@nt4f04uNd nt4f04uNd commented Jan 21, 2023

Copy link
Copy Markdown
Contributor

Adds AudioService.setFallbackArt that automatically loads arts for all platforms using the existing refactored dart code.

Also fixes a bug with loadThumbnailUri where it was never used, which became obvious from another necessary change - reporting all errors from the native side to dart, to be able to fallback to default art.

Tested only on Android for now, this will need to be tested on other platforms

Fixes #666
Fixes #309

I wrote this PR because I needed this in my app. You can see how I'm using this API there if you want, there's also a video nt4f04uNd/sweyer#80

Record_2023-01-22-01-01-47.mp4

Pre-launch Checklist

  • I read the CONTRIBUTING.md and followed the process outlined there for submitting PRs.
  • My change is not breaking and lands in minor branch OR my change is breaking and lands in major branch.
  • If I'm the first to contribute to the next version, I incremented the version number in pubspec.yaml according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change (format: * DESCRIPTION OF YOUR CHANGE (@your-git-username)).
  • I updated/added relevant documentation (doc comments with ///).
  • I ran dart analyze.
  • I ran dart format.
  • I ran flutter test and all tests are passing.

@nt4f04uNd

Copy link
Copy Markdown
Contributor Author

Defining it as a static method on AudioService has turned out to be a bit messy as it tries to handle when initialisation methods are called out of order and the handler is(n't) ready yet. Some alternatives:

  1. The fallback parameters can be part of the init config object
  2. They can be separate parameters of the init method
  3. They can be properties of the handler so that different handlers can have different fallbacks
  4. They can be callback functions passed into the init method that take the url and handler as context parameters similar to how the placeholder and error images are handled in cached_network_image.

Hmm..

The primary reason the API is currently like this is because I need to be able to update the art dynamically. I considered options like 1, 2 and 4, but they don't allow this. Although, I never thought of the 3rd one, which also allows this and looks much better. Thanks for suggesting it :-)

I will try to make this working, for now I'll leave this PR as a draft.

@ryanheise

Copy link
Copy Markdown
Owner

But Option 4 (like cached_network_image) can handle your use case as well, because it's a callback function. In the implementation of that function, you can dynamically adjust your desired behaviour.

@ruchit-7span

Copy link
Copy Markdown
Contributor

@nt4f04uNd
AudioService.setFallbackArt method is working great for mobile.
But it is not working for android auto's song library.
I am showing default image from my assets and that image is showing in notification.
But it is not working for media library in android auto.

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.

Default album art Fallback image for media items with missing arts

3 participants