我正在尝试使用 TagLib 读取存储在 IsolatedStorage 中的 mp3 文件的元数据。我知道 TagLib 通常只将文件路径作为输入,但由于 WP 使用沙盒环境,我需要使用流。
按照本教程(http://www.geekchamp.com/articles/reading-and-writing-metadata-tags-with-taglib)我创建了一个 iFileAbstraction 接口:
public class SimpleFile
{
public SimpleFile(string Name, Stream Stream)
{
this.Name = Name;
this.Stream = Stream;
}
public string Name { get; set; }
public Stream Stream { get; set; }
}
public class SimpleFileAbstraction : TagLib.File.IFileAbstraction
{
private SimpleFile file;
public SimpleFileAbstraction(SimpleFile file)
{
this.file = file;
}
public string Name
{
get { return file.Name; }
}
public System.IO.Stream ReadStream
{
get { return file.Stream; }
}
public System.IO.Stream WriteStream
{
get { return file.Stream; }
}
public void CloseStream(System.IO.Stream stream)
{
stream.Position = 0;
}
}
通常我现在可以这样做:
using (IsolatedStorageFileStream filestream = new IsolatedStorageFileStream(name, FileMode.OpenOrCreate, FileAccess.ReadWrite, store))
{
filestream.Write(data, 0, data.Length);
// read id3 tags and add
SimpleFile newfile = new SimpleFile(name, filestream);
TagLib.Tag tags = TagLib.File.Create(newfile);
}
问题是 TagLib.File.Create 仍然不想接受 SimpleFile 对象。我该如何进行这项工作?