5

Is it possible edit Tags of an ByteArray which represents a Mp3-File with TagLib#?

At the moment I need to do it this way:

System.IO.File.WriteAllBytes(path + file + ".mp3", byt);
TagLib.File f = TagLib.File.Create(path + song + ".mp3");

Is it possible to avoid this and create the TagLib.File directly from a ByteArray?

1 Answers1

4

Try this:

var file = TagLib.File.Create(new FileBytesAbstraction(<file name>, <file bytes>));

Where FileBytesAbstraction is:

public class FileBytesAbstraction : TagLib.File.IFileAbstraction
{
    public FileBytesAbstraction(string name, byte[] bytes)
    {
        Name = name;

        var stream = new MemoryStream(bytes);
        ReadStream = stream;
        WriteStream = stream;
    }

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

    public string Name { get; private set; }

    public Stream ReadStream { get; private set; }

    public Stream WriteStream { get; private set; }
}
  • I was searching something about this and this is the best response that I see. Thanks for the example. – amelian Mar 17 '17 at 08:25