audio_service icon indicating copy to clipboard operation
audio_service copied to clipboard

MediaItem ArtUri from asset

Open b1jarosz opened this issue 5 years ago • 5 comments

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

b1jarosz avatar Nov 12 '20 18:11 b1jarosz

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());

ryanheise avatar Nov 19 '20 12:11 ryanheise

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;
}

from Harjinder Bains - Stackoverflow response

Then i edited a bit to use app directory dir and changed to direct Uri response.

chaerf avatar Aug 18 '22 05:08 chaerf

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.

ryanheise avatar Aug 18 '22 06:08 ryanheise

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.

chaerf avatar Aug 18 '22 16:08 chaerf

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

rahul-mobilecoderz avatar Feb 27 '23 09:02 rahul-mobilecoderz