我想在我的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)
答案 0 :(得分:2)
您可以使用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; }
}
答案 1 :(得分:0)
不能这样做。使用了MusicProperties,然后使用lastfm api来获取所需的信息..在Win8中很难羞耻#在普通的C#中很容易#
答案 2 :(得分: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