Samurai016 / Audiotagger

This library allow you to read and write ID3 tags to MP3 files.
https://pub.dev/packages/audiotagger
MIT License
23 stars 20 forks source link

[Question / need assistance]: Java Exception thrown while editing the tags #7

Closed chrissiwaffler closed 4 years ago

chrissiwaffler commented 4 years ago

Hello there, After i downloaded a .mp3 file of the internet i want to edit the ID3 Tags using this dart extension. After the method writeTagsFromMap() is called, i got the following exception printed out in my debugging console:

W/System.err(11010): org.jaudiotagger.audio.exceptions.InvalidAudioFrameException: No audio header found within Conversations.mp3
W/System.err(11010):    at org.jaudiotagger.audio.mp3.MP3AudioHeader.<init>(MP3AudioHeader.java:141)
W/System.err(11010):    at org.jaudiotagger.audio.mp3.MP3File.<init>(MP3File.java:424)
W/System.err(11010):    at org.jaudiotagger.audio.mp3.MP3FileReader.read(MP3FileReader.java:39)
W/System.err(11010):    at org.jaudiotagger.audio.AudioFileIO.readFile(AudioFileIO.java:356)
W/System.err(11010):    at org.jaudiotagger.audio.AudioFileIO.read(AudioFileIO.java:193)
W/System.err(11010):    at com.nicolorebaioli.audiotagger.AudiotaggerPlugin.writeTags(AudiotaggerPlugin.java:88)
W/System.err(11010):    at com.nicolorebaioli.audiotagger.AudiotaggerPlugin.onMethodCall(AudiotaggerPlugin.java:64)
W/System.err(11010):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
W/System.err(11010):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
W/System.err(11010):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
W/System.err(11010):    at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(11010):    at android.os.MessageQueue.next(MessageQueue.java:336)
W/System.err(11010):    at android.os.Looper.loop(Looper.java:197)
W/System.err(11010):    at android.app.ActivityThread.main(ActivityThread.java:8016)
W/System.err(11010):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err(11010):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W/System.err(11010):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

This is my source code (of the editing class):

import 'package:audiotagger/audiotagger.dart';
import 'package:youtube_downloader/index.dart';

class MetadataEditor2 {

  Audiotagger tagger;

  MetadataEditor2() {
    tagger = new Audiotagger();
  }

  Future _checkPermissions() async {
    // Request permission to write in an external directory.
    // (In this case downloads)
    if (!await Permission.storage.request().isGranted) {
      await _checkPermissions();
    }
  }

  Future<void> setTags(String filePath, String title, String artist, String album) async {
    final tags = <String, String> {
      "title": title,
      "artist": artist,
      "album": album
    };
    _checkPermissions();

    final result = await tagger.writeTagsFromMap(path: filePath, tags: tags);
    print("Schreiben: " + result.toString());
  }

}

Note: The method tagger.writeTagsFromMap() returns false.

Samurai016 commented 4 years ago

Hi, probably the problem is the file, sometimes you download a file with .mp3 extension but actually it is a .webm file. In that case, try to convert it using flutter_ffmpeg with the command:

var command = "-i \"$songPath\" -vn -ab 128k -ar 44100 -y \"$outputPath\"";
chrissiwaffler commented 4 years ago

Sounds good, i will try that command soon and post my results!

Thank you very much!

chrissiwaffler commented 4 years ago

I tested it and it WORKED! The method now returns true and the tags of the .mp3-file are edited.

I will close this.

Thank you very much!