Reputation: 5497
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)
Upvotes: 1
Views: 685
Reputation: 345
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
Upvotes: 0
Reputation: 9522
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; }
}
Upvotes: 3
Reputation: 5497
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#
Upvotes: 0