2019-05-20 00:21:54 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
2019-07-05 18:17:09 +00:00
|
|
|
namespace Aurora.Models.Media
|
2019-05-20 00:21:54 +00:00
|
|
|
{
|
2019-05-24 14:27:19 +00:00
|
|
|
public class LocalAudio : BaseMedia
|
2019-05-20 00:21:54 +00:00
|
|
|
{
|
2019-05-24 14:27:19 +00:00
|
|
|
public LocalAudio(FileInfo fileInfo)
|
2019-05-20 00:21:54 +00:00
|
|
|
{
|
|
|
|
File = fileInfo;
|
2019-05-24 19:59:26 +00:00
|
|
|
LoadMetadata();
|
2019-05-20 00:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
public FileInfo File { get; private set; }
|
|
|
|
|
2019-05-24 21:17:14 +00:00
|
|
|
public override BaseMetadata Metadata { get; protected set; }
|
2019-05-24 19:59:26 +00:00
|
|
|
|
|
|
|
public override MediaTypeEnum MediaType
|
|
|
|
{
|
|
|
|
get { return MediaTypeEnum.Audio; }
|
|
|
|
}
|
|
|
|
|
2019-05-20 00:21:54 +00:00
|
|
|
#endregion Properties
|
|
|
|
|
2019-05-24 14:27:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Override load method.
|
|
|
|
/// </summary>
|
2019-05-22 14:30:41 +00:00
|
|
|
public override void Load()
|
2019-05-20 00:21:54 +00:00
|
|
|
{
|
2019-05-22 14:30:41 +00:00
|
|
|
if (this.DataStream != null)
|
|
|
|
{
|
|
|
|
DataStream.Close();
|
|
|
|
DataStream = null;
|
|
|
|
}
|
|
|
|
this.DataStream = System.IO.File.OpenRead(File.FullName);
|
|
|
|
base.Load();
|
2019-05-20 00:21:54 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 14:27:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Override unload method
|
|
|
|
/// </summary>
|
2019-05-22 14:30:41 +00:00
|
|
|
public override void Unload()
|
|
|
|
{
|
|
|
|
if (this.DataStream != null)
|
|
|
|
{
|
|
|
|
DataStream.Close();
|
|
|
|
DataStream = null;
|
|
|
|
}
|
|
|
|
base.Unload();
|
|
|
|
}
|
2019-05-24 19:59:26 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|
2019-05-20 00:21:54 +00:00
|
|
|
}
|
|
|
|
}
|