JeevanJames / Id3

Library to read, modify and write ID3 & Lyrics3 tags in MP3 files. Provides an extensible framework for retrieving ID3 information from online services.
Apache License 2.0
41 stars 17 forks source link

Delete Pictures Tag #23

Closed Aoi-hosizora closed 4 years ago

Aoi-hosizora commented 5 years ago

I use tag.Pictures.Clear() and tag.Remove<Id3.Frames.PictureFrame>() to delete the picture frame of mp3 file, but both of these methods will let the music player(I have tried WMP and MPC-HC) work abnormally, (when I use WMP, it will try to decode the mp3 file and then crash). Here is my code:

public static bool ClearMp3Cover(Mp3 mp3) {
    Id3Tag tag = mp3.GetTag(Id3TagFamily.Version2X);

    if (tag.Pictures != null) {
        // tag.Remove<Id3.Frames.PictureFrame>();
        tag.Pictures.Clear();
    }
    return mp3.UpdateTag(tag);
    // return mp3.WriteTag(tag, WriteConflictAction.Replace);
}

image image

Aoi-hosizora commented 4 years ago

I have found that if I directly clear tag.Picture and mp3.UpdateTag(tag), the mp3 file size won't be small. But if I use mp3.DeleteTag(Id3TagFamily.Version2X) before UpdateTag, it won't raise any problem!

public static bool ClearMp3Cover(Mp3 mp3) {
    Id3Tag tag = mp3.GetTag(Id3TagFamily.Version2X);

    if (tag.Pictures != null) {
        tag.Pictures.Clear();
    }

    mp3.DeleteTag(Id3TagFamily.Version2X);
    return mp3.UpdateTag(tag);
}