0
 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。

4

1 回答 1

0

你可以看看save 方法的实现。

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);
}

我只报告了当前实现的代码,我没有测试或编译。

于 2013-09-03T12:11:56.370 回答