MediaItem ArtUri from asset
Is your feature request related to a problem? Please describe. I'm trying to set song image/cover from app asset
Describe the solution you'd like currently it's supporting file path, I'd like to add asset i.e. as regular Image.asset
Describe alternatives you've considered I tried to get app directory uri but I failed
Additional context nil
This is a duplicate of #347 although I'll redirect the other issue here since you have done a nice job of following the template structure.
Note that until this feature is implemented, you can extract the asset into a file first (e.g. the first time the app is launched) and then use a file:// URL as your artUri. To extract the asset, use this code:
await file.writeAsBytes((await rootBundle.load(assetPath)).buffer.asUint8List());
I'd issues writing users device storage, requesting permission to write just to use an asset image it's ugly, so i found this: using path_provider package to get app's directory (as suggested)
Future<Uri> getImageFileFromAssets(String path) async {
final byteData = await rootBundle.load('assets/$path');
final buffer = byteData.buffer;
Directory tempDir = await getApplicationDocumentsDirectory()
String tempPath = tempDir.path;
var filePath =
tempPath + '/file_01.tmp'; // file_01.tmp is dump file, can be anything
return (await File(filePath).writeAsBytes(
buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes)))
.uri;
}
Then i edited a bit to use app directory dir and changed to direct Uri response.
I would suggest using path provider and get the app's cache directory which is private to the app and marked as something that can be deleted by the system if necessary to free up storage later.
I would suggest using path provider and get the app's cache directory which is private to the app and marked as something that can be deleted by the system if necessary to free up storage later.
You'r right, just edited using path_provider package.
Please. try this solution link:https://stackoverflow.com/questions/75456939/how-to-show-artmusic-on-media-control-notification-from-assets-file-in-flutter/75578627#75578627