我正在尝试使用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对象。我该怎么做呢?
发布于 2014-01-26 06:35:14
您的代码无法编译,因为TagLib.File.Create希望输入为IFileAbstraction,而您为其提供的SimpleFile实例并未实现接口。这里有一种修复方法:
// read id3 tags and add
SimpleFile file1 = new SimpleFile( name, filestream );
SimpleFileAbstraction file2 = new SimpleFileAbstraction( file1 );
TagLib.Tag tags = TagLib.File.Create( file2 );不要问我为什么我们需要SimpleFile类,而不是将名称和流传递到SimpleFileAbstraction中-它在您的示例中。
发布于 2020-11-11 12:12:08
是我,还是为什么TagLib.Create()不能简单地重载一个路径?为什么这件事这么复杂?(至少我觉得太难了)
发布于 2014-01-22 06:55:32
你可以尝试这样做:MusicProperties class对你来说应该足够了,而且使用起来更容易。
https://stackoverflow.com/questions/21239918
复制相似问题