FileStream fs = new FileStream(filename,FileMode.Open,FileAccess.Read);
MemoryStream ms = new MemoryStream();
fs.CopyTo(ms);
ms.Seek(0, SeekOrigin.Begin);
IdSharp.Tagging.ID3v2.IID3v2 tags = IdSharp.Tagging.ID3v2.ID3v2Helper.CreateID3v2(ms);
// here i am changing year to new value
tags.Year = "2012";
tags.Save("path"); // here it is asking for file path.
我的任务是读取和写入id3v2标签到mp3流。但是在这种情况下保存方法是将字符串路径作为参数。有没有办法做到这一点? 目前我正在使用idsharp dll。
答案 0 :(得分:0)
您可以查看the save method的实现。
int originalTagSize = IdSharp.Tagging.ID3v2.ID3v2Tag.GetTagSize(filename);
byte[] tagBytes = tags.GetBytes(originalTagSize);
if (tagBytes.Length < originalTagSize)
{
// Eventually this won't be a problem, but for now we won't worry about shrinking tags
throw new Exception("GetBytes() returned a size less than the minimum size");
}
else if (tagBytes.Length > originalTagSize)
{
//In the original implementation is done with:
//ByteUtils.ReplaceBytes(path, originalTagSize, tagBytes);
//Maybe you should write a 'ReplaceBytes' method that accepts a stream
}
else
{
// Write tag of equal length
ms.Write(tagBytes, 0, tagBytes.Length);
}
我只报告了当前实现的代码,我还没有测试过或编译过。