using System;
using System.IO;
namespace Aurora.Backend.Models.Media
{
public class LocalAudio : BaseMedia
{
public LocalAudio(FileInfo fileInfo)
{
File = fileInfo;
LoadMetadata();
}
#region Properties
public FileInfo File { get; private set; }
public override BaseMetadata Metadata { get; protected set; }
public override MediaTypeEnum MediaType
{
get { return MediaTypeEnum.Audio; }
}
#endregion Properties
///
/// Override load method.
///
public override void Load()
{
if (this.DataStream != null)
{
DataStream.Close();
DataStream = null;
}
this.DataStream = System.IO.File.OpenRead(File.FullName);
base.Load();
}
///
/// Override unload method
///
public override void Unload()
{
if (this.DataStream != null)
{
DataStream.Close();
DataStream = null;
}
base.Unload();
}
private void LoadMetadata()
{
TagLib.File tagFile = TagLib.File.Create(File.FullName);
Metadata = new AudioMetadata()
{
Title = tagFile.Tag.Title,
Album = tagFile.Tag.Album,
Artist = tagFile.Tag.FirstAlbumArtist,
ExtraData = tagFile.Tag
};
}
}
}