KRTirtho / metadata_god

Audio file Metadata reading and writing library for Flutter
MIT License
23 stars 12 forks source link

Why FrbAnyhowException is throwing? What is going wrong? #28

Open s681562 opened 8 months ago

s681562 commented 8 months ago

minSdk 29 targetSdk 34 compileSdk 34

I/flutter (16667): #### writeAudioTagArtist file path /storage/emulated/0/Recordings/Call/통화 녹음 010aaaaxxxx_240308_160557.m4a I/flutter (16667): ###### writeAudioTagArtist exception Instance of 'FrbAnyhowException' I/flutter (16667): #0 FlutterRustBridgeBase._transformRust2DartMessage (package:flutter_rust_bridge/src/basic.dart:133) I/flutter (16667): #1 FlutterRustBridgeBase.executeNormal. (package:flutter_rust_bridge/src/basic.dart:70)

FAILED Metadata metadata = await MetadataGod.readMetadata(file: path);

What I am executed:

Future writeAudioTagArtist(String path, String phone) async { final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin(); AndroidDeviceInfo info = await deviceInfoPlugin.androidInfo; int sdkVersion = info.version.sdkInt; if (Platform.isAndroid && sdkVersion <= 32) { final bool hasStorageAccess = await Permission.storage.isGranted; if(!hasStorageAccess) { await Permission.storage.request(); if (!await Permission.storage.isGranted) { print("#### writeAudioTagArtist Permission.storage not granted"); return; } } }

print("#### writeAudioTagArtist file path ${path}");

try {
  // Get metadata from file
  Metadata metadata = await MetadataGod.readMetadata(file: path);
  print("#### A${phone}");
  print("#### A${path}");
  print("#### A${metadata}");
  // Set metadata to file
  await MetadataGod.writeMetadata(file: path, metadata:
  Metadata(
    title: phone,
    artist: phone,
    albumArtist: phone,
    genre: phone,
  ),
  );

  Metadata metadataA = await MetadataGod.readMetadata(file: path);
  print("#### TITLE ${metadataA.title}");
  print("#### ARTIST ${metadataA.artist}");
  print("#### ALBUM ${metadataA.albumArtist}");
  print("#### GENRE ${metadataA.genre}");
} catch (error, stack) {
  print("###### writeAudioTagArtist exception ${error}");
  print(stack);
}

}

Please help. Thanks in advance.

arrahmanbd commented 4 months ago

It's an error occured when reading metadata of a file without having anymetadata/tag. When No tags found, creating a new tag of type Id3v2 also caused this error of metadata_god package. Try using try-cartch-finally handeling method.

arrahmanbd commented 4 months ago

Best solution is:

try{
// Fetch metadata for each song
Metadata filemetadata = await MetadataGod.readMetadata(file: songFile.path);
}
catch (e) {
// Handle individual file metadata errors
print("Error reading metadata for ${songFile.path}: $e");
// Skip the current file and continue with the next one
continue;
}