How do I use TagLib-Sharp to write custom (PRIV) ID3 frames?

扶醉桌前 提交于 2019-12-23 01:52:50

问题


Specifically, I'd like to write the Windows Media Player frames, such as theWM/MediaClassPrimaryID, WM/MediaClassSecondaryID and WM/WMCollectionGroupID frames.

I'm using PowerShell, but C# would be good too.


回答1:


I'm a bit rusty, but the following should be mostly correct. I remember these tags being UTF-16 but you'll probably want to get an existing tag and try decoding its value with the Unicode encoder to be sure.

// Get or create the ID3v2 tag.
TagLib.Id3v2.Tag id3v2_tag = file.GetTag(TagLib.TagTypes.Id3v2, true);

if(id3v2_tag != null) {
    // Get the private frame, create if necessary.
    PrivateFrame frame = PrivateFrame.Get(id3v2_tag, "WM/MediaClassPrimaryID", true);

    // Set the frame data to your value.  I am 90% sure that these are encoded with UTF-16.
    frame.PrivateData = System.Text.Encoding.Unicode.GetBytes(value);
}


来源:https://stackoverflow.com/questions/8793640/how-do-i-use-taglib-sharp-to-write-custom-priv-id3-frames

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!