1

我想在我的 Windows 应用商店项目中使用 TagLib。TagLib 是作为参考导入的,它的 dll (taglib-sharp.dll) 我可以访问我的音乐文件夹中的任何文件,因为它已被检查功能。但是,当我打电话时

TagLib.File file = TagLib.File.Create(soundFilePath, TagLib.ReadStyle.None); 

它引发以下错误:

System.UnauthorizedAccessException was unhandled by user code
HResult=-2147024891
Message=Access to the path 'C:\Users\Gabor\Music\_FIFA 2010 soundtracks\01. Meine Stadt - Auletta.mp3' is denied.
Source=taglib-sharp
StackTrace:
   at TagLib.File.Create(IFileAbstraction abstraction, String mimetype, ReadStyle propertiesStyle)
   at TagLib.File.Create(String path, String mimetype, ReadStyle propertiesStyle)
   at TagLib.File.Create(String path, ReadStyle propertiesStyle)
4

3 回答 3

3

您可以使用 TagLibSharp 通过创建 StreamFileAbstraction 并将其传递给 File.Create 来加载标签。这不会使用任何被禁止的 API。

public void ExampleCall(StorageFile storageFile)
{
    IRandomAccessStreamWithContentType f = await storageFile.OpenReadAsync();
    var file = File.Create(new StreamFileAbstraction(storageFile.Name, f.AsStream()));
}

public class StreamFileAbstraction : File.IFileAbstraction
{
    public StreamFileAbstraction(string name, Stream stream)
    {
        Name = name;
        ReadStream = stream;
        WriteStream = stream;
    }

    public void CloseStream(Stream stream)
    {
        stream.Flush();
    }

    public string Name { get; private set; }
    public Stream ReadStream { get; private set; }
    public Stream WriteStream { get; private set; }
}
于 2012-12-30T23:11:58.610 回答
0

不能这样做。改用 MusicProperties,然后使用 lastfm api 来获取所需的信息.. 可惜它在 Win8 c# 中如此困难在普通 C# 中很容易

于 2012-11-16T19:28:09.717 回答
0

对于 WinRT,您接下来需要:

var task = await StorageFile.GetFileFromApplicationUriAsync(uri);
var stream = await task.OpenStreamForReadAsync();
 using (var info = File.Create(new StreamFileAbstraction(Path.GetFileName(uri.LocalPath), stream, stream)))
 {
      Album = info.Tag.Album;
      Comment = info.Tag.Comment;
      // more properties
 }

你需要添加 NuGet 包 - TagLib# Portable

于 2015-03-10T22:32:59.347 回答