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

Unable to Add an ID3.v2 Tag to an MP3 #65

Open
BourgeoisDirk opened this issue Feb 19, 2023 · 2 comments
Open

Unable to Add an ID3.v2 Tag to an MP3 #65

BourgeoisDirk opened this issue Feb 19, 2023 · 2 comments

Comments

@BourgeoisDirk
Copy link

BourgeoisDirk commented Feb 19, 2023

Hey, so far this is one of the most convenient ID3 Tag Editors I've come across.
Only thing is, I can't actually Add an ID3 tag to a freshly created MP3.

    _private void ApplyID3Tags(string filepath)
    {
        using (var file = new Mp3(filepath, Mp3Permissions.ReadWrite))
        {
            var tag = file.GetTag(Id3TagFamily.Version2X);
            if (tag == null)
                tag = new Id3Tag();
            
            tag.Title = Title;
            
            if (!file.WriteTag(tag, WriteConflictAction.Replace))
                throw new Exception("Applying ID3 Tags Failed");
        }
    }_

This seems simple enough, but I get this error on the "file.WriteTag()" function at the end: "Sequence contains no matching element"

System.InvalidOperationException
HResult=0x80131509
Message=Sequence contains no matching element
Source=System.Linq
StackTrace:
at System.Linq.ThrowHelper.ThrowNoMatchException()
at Id3.Id3Handler.GetHandler(Id3Version version)
at Id3.Mp3.WriteTag(Id3Tag tag, WriteConflictAction conflictAction)

Any clue as to why I can't add an ID3 tag ?
PS: GetTag() resulted in null, so i added "new Id3Tag()"
Also, "file.AvailableTagVersions" count = 0

@BourgeoisDirk
Copy link
Author

BourgeoisDirk commented Feb 20, 2023

Full code segment:

    _private void ApplyID3Tags_Test(string filepath)
    {
        using (var file = new Id3.Mp3(filepath, Id3.Mp3Permissions.ReadWrite))
        {
            var tag = file.GetTag(Id3.Id3TagFamily.Version2X);
            if (tag == null)
                tag = new Id3.Id3Tag();

            tag.Track = Track;
            tag.AudioSourceUrl = Url;
            tag.ArtistUrls.Add(new Id3.Frames.ArtistUrlFrame(Channel?.uChannel.Url));
            tag.Artists.Value.Add(Channel?.Title);
            tag.Album = (Playlist == null ? Channel?.Title : Playlist?.Title);
            tag.Title = Title;
            tag.Subtitle = Description;
            tag.RecordingDate = UploadDate.DateTime;
            tag.Length = Duration;
            foreach (var word in Keywords)
                tag.Comments.Add(word);
            if (Thumbnail != null)
                tag.Pictures.Add(new Id3.Frames.PictureFrame()
                {
                    Description = "Thumbnail",
                    PictureData = Thumbnail.ToByteArray(),
                    PictureType = Id3.Frames.PictureType.FrontCover
                });

            if (!file.WriteTag(tag, Id3.WriteConflictAction.Replace))
                throw new Exception("Applying ID3 Tags Failed");
        }
    }_

@akdoroshenko
Copy link

Try this approach:
file.WriteTag(tag, Id3Version.V23, WriteConflictAction.Replace);

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