4

I just created a little program which allows me to change the details of an audio file.

I want to change:

  • Title
  • AlbumArtist
  • Performers
  • Album
  • Picture

The taglib library allows me to change different kinds of audio files with the exact same code.

For me, the following code works completely fine with the extensions .m4a and mp3, but as soon as I tried to also change some .wma files, a strange error occured.

public void changeAttributes(string filePath, string title, string interpret, string album)
{
    TagLib.File file = TagLib.File.Create(filePath);

    file.Tag.Title = title;                                 //Titel
    file.Tag.AlbumArtists = new String[] {interpret};       //AlbumArtist
    file.Tag.Performers = new String[] { interpret };       //Performers
    if (!album.Equals("")) { file.Tag.Album = album; }      //Album (if there is no album given, it won´t be overwritten)

    if (!albumCoverPath.Equals("")) {
        file.Tag.Pictures = new IPicture[] { (IPicture)new Picture(albumCoverPath) };
    }   //Album-Cover (if there is no image given, it won´t be overwritten)

    file.Save();
}

Once I put the three .wma-files into the folder I was testing in, The code stopped and got me into the debugger at the line file.Save(); with the error

System.ArgumentOutOfRangeException: "Size is less than zero."

When checking the file-object in the debugger I can´t find anything that would explain the occurrence of the error.

EDIT:

Once I removed the line which changes the AlbumArtists, the Code runs just fine.

And after once changing everything but the AlbumArtists, I can insert the line of code again and it runs without errors. Can anyone tell me how this strange behavior came about?

Any suggestions?

Tim Schmidt
  • 1,297
  • 1
  • 15
  • 30
  • I'm doing some research to make sure WMA are supported but I'm unable to find a safe result. Sorry about the answer – Bruno Avelar Aug 16 '17 at 18:30
  • I couldn't find anything regarding to this seither. But thaks anyway, all help is appreciated. – Tim Schmidt Aug 16 '17 at 18:43
  • @TimSchmidt, did you ever figure out what the problem is here? I just ran into this issue by doing this `$tag = [TagLib.File]::Create($file.FullName); $tag.tag.title = $newTitle; $tag.Save()` and got the error you referenced. – incutonez Mar 03 '19 at 03:36
  • 1
    As a follow-up, I ended up using [this answer](https://stackoverflow.com/a/49028384/1253609) to fix the issue above. – incutonez Mar 03 '19 at 19:29
  • @incutonet No, I decided that I dont´care ^^ but good to see that you solved your problem, also thanks for providing the link to the solution you used. – Tim Schmidt Mar 04 '19 at 13:57

0 Answers0