Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Flutter web for media files without album art #28

Open
50n13x opened this issue Apr 22, 2022 · 2 comments
Open

Error on Flutter web for media files without album art #28

50n13x opened this issue Apr 22, 2022 · 2 comments

Comments

@50n13x
Copy link

50n13x commented Apr 22, 2022

Hi,

Following piece of code:

FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true);
  if (result != null) {
  for(int x = 0; x < result.files.length; x++) {
    print(result.files[x].name);
    Uint8List bytes = result.files[x].bytes as Uint8List;
    final metadata = await MetadataRetriever.fromBytes(bytes); // throws the error
    String? trackName = metadata.trackName;
    print(trackName);

[...]

I checked this with mp3, m4a and wmv files. It only occurs on Flutter web. If the audio files contain an album art everything works fine. If they do not contain an album art, I get the following error message:

Error: Expected a value of type 'String', but got one of type 'Null'
at Object.throw_ [as throw] (http://localhost:50323/dart_sdk.js:5067:11)
at Object.castError (http://localhost:50323/dart_sdk.js:5026:15)
at Object.cast [as as] (http://localhost:50323/dart_sdk.js:5351:17)
at Function.as (http://localhost:50323/dart_sdk.js:46170:19)
at http://localhost:50323/packages/flutter_media_metadata/src/flutter_media_metadata_web.dart.lib.js:89:159
at Object._checkAndCall (http://localhost:50323/dart_sdk.js:5274:16)
at Object.dcall (http://localhost:50323/dart_sdk.js:5279:17)
at ret (http://localhost:50323/dart_sdk.js:62346:21)

Afaik this relates to the following line of code:

let metadata = new (T.IdentityMapOfString$dynamic()).from(["metadata", new _js_helper.LinkedMap.new(), "albumArt", convert.base64Decode(core.String.as(dart.dsend(rawMetadataJson, '_get', ["Cover_Data"]))), "filePath", null]);

I cannot read nor write .js :) but it looks like a null check is missing?

What else do you need?

Thanks,
Michael

@50n13x
Copy link
Author

50n13x commented Apr 22, 2022

FYI, with the following quick fix it seems to work:

flutter_media_metadata_web.dart: line 109 -113:

           final metadata = <String, dynamic>{
              'metadata': {},
              'albumArt': base64Decode(rawMetadataJson['Cover_Data']),
              'filePath': null,
            };

replaced by:

            var metadata = <String, dynamic>{};
            if (rawMetadataJson['Cover_Data'] != null) {
              metadata = <String, dynamic>{
                'metadata': {},
                'albumArt': base64Decode(rawMetadataJson['Cover_Data']),
                'filePath': null,
              };
            } else {
              metadata = <String, dynamic>{
                'metadata': {},
                'albumArt': null,
                'filePath': null,
              };
            }

Haven't yet checked if an album art is derived it the file contains one.

@iliyami
Copy link

iliyami commented Dec 10, 2022

It's right and I have the same issue.

Error: Expected a value of type 'String', but got one of type 'Null'
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 99:3 castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 452:10 cast
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 705:17 as
packages/flutter_media_metadata/src/flutter_media_metadata_web.dart 111:31
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14 _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39 dcall
Application finished.

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

No branches or pull requests

2 participants