3

I'm trying to read the metadata of a mp3 file stored in IsolatedStorage using TagLib. I know TagLib normally only take a file path as input but as WP uses a sandbox environment I need to use a stream.

Following this tutorial (http://www.geekchamp.com/articles/reading-and-writing-metadata-tags-with-taglib) I created a iFileAbstraction interface:

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

Normally I would now be able to do this:

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

The problem is that TagLib.File.Create still doesn't want to accept the SimpleFile object. How do I make this work?

Philippe Maes
  • 510
  • 9
  • 26

1 Answers1

4

Your code doesn't compile because TagLib.File.Create wants IFileAbstraction on input, and you're giving it SimpleFile instance which doesn't implement the interface. Here's one way to fix:

// read id3 tags and add
SimpleFile file1 = new SimpleFile( name, filestream );
SimpleFileAbstraction file2 = new SimpleFileAbstraction( file1 );
TagLib.Tag tags = TagLib.File.Create( file2 );

Don't ask me why we need SimpleFile class instead of passing name and stream into SimpleFileAbstraction - it was in your sample.

Soonts
  • 20,079
  • 9
  • 57
  • 130
  • Thanks, but now I get a System.TypeLoadException on "TagLib.Tag tags = TagLib.File.Create( file2 );" – Philippe Maes Jan 26 '14 at 16:55
  • Look at the exception in debugger: it usually tells you which type has failed to load, and why. – Soonts Jan 28 '14 at 04:35
  • "Type 'TagLib.Id3v2.Tag' from assembly 'taglib-sharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0' is attempting to implement an inaccessible interface." – Philippe Maes Jan 28 '14 at 18:07
  • 1
    Well, it looks like TagLib is incompatible with windows phone. TagLib is open source, so you can either debug it (I'd start with this option but wouldn’t invest more than a few hours in that), or (if the license permits) copy-paste relevant source files to your project, or just create your own solution using TagLib as a reference and for tests. – Soonts Jan 29 '14 at 17:08