LucJosin / on_audio_query

Flutter Plugin used to query audios/songs infos [title, artist, album, etc..] from device storage.
https://pub.dev/packages/on_audio_query
44 stars 28 forks source link

[furture request] Is it possible to get the cover of a flac file #126

Closed huangcs427 closed 1 year ago

huangcs427 commented 1 year ago

My code is as follows

  Future<String> createCoverPath({
    required int id,
    required String fileName,
    int quality = 100,
    ArtworkType type = ArtworkType.AUDIO,
    ArtworkFormat format = ArtworkFormat.PNG,
  }) async {
    try {
      Directory tempPath = await getTemporaryDirectory();
      final coverPath = getCoverPath(tempPath, fileName);
      final File file = File(coverPath);
      if (!await file.exists()) {
        await file.create();
        final Uint8List? image = await audioQuery.queryArtwork(
          id,
          type,
          format: format,
          size: coverSize,
          quality: quality,
        );
        file.writeAsBytesSync(image!);
      }
      return file.path;
    } catch (e) {
      print("$fileName => get cover error: $e");
      return '';
    }
  }