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?