c# windows store app granting capabilities to used dll-s

感情迁移 提交于 2019-12-11 04:53:24

问题


I'd like to use TagLib in my Windows Store project. The TagLib is imported as reference, with its dll ( taglib-sharp.dll ) I can access any file in my music folder since it is checked in the capabilities. However, when I call

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

it throws the following error:

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)

回答1:


You can use TagLibSharp to load tags by creating a StreamFileAbstraction and passing that to File.Create. This won't use any banned APIs.

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



回答2:


couldn't do it this way. used MusicProperties instead, and then used lastfm api to get the needed info.. shame its so difficult in Win8 c# what is easy in normal C#




回答3:


For WinRT you need next:

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
 }

and you need add NuGet Packages - TagLib# Portable



来源:https://stackoverflow.com/questions/13381494/c-sharp-windows-store-app-granting-capabilities-to-used-dll-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!