Added base classes to encapsulate metadata in media
This commit is contained in:
35
Aurora/Backend/Models/Media/AudioMetadata.cs
Normal file
35
Aurora/Backend/Models/Media/AudioMetadata.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
|
||||
namespace Aurora.Backend.Models.Media
|
||||
{
|
||||
public class AudioMetadata : BaseMetadata
|
||||
{
|
||||
public void AutioMetadata()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The title of the song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The artist of the song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Artist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The album from which the song belongs.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Album { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The duration of the song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Duration { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Aurora.Backend.Models
|
||||
namespace Aurora.Backend.Models.Media
|
||||
{
|
||||
public abstract class BaseMedia
|
||||
{
|
||||
@ -17,36 +17,6 @@ namespace Aurora.Backend.Models
|
||||
#region Properties
|
||||
public string Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The title of the song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The artist of the song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Artist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The album from which the song belongs.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Album { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The duration of the song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string Duration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Extra data associated with a song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public object Metadata { get; set; }
|
||||
|
||||
#endregion Properties
|
||||
|
||||
public virtual void Load()
|
||||
@ -59,6 +29,9 @@ namespace Aurora.Backend.Models
|
||||
_loaded = false;
|
||||
}
|
||||
|
||||
public abstract MediaTypeEnum MediaType { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data stream that holds the song.
|
||||
/// </summary>
|
||||
@ -67,10 +40,6 @@ namespace Aurora.Backend.Models
|
||||
{
|
||||
get
|
||||
{
|
||||
//if (!_loaded)
|
||||
//{
|
||||
// throw new InvalidOperationException("Must be loaded first");
|
||||
//}
|
||||
return _stream;
|
||||
}
|
||||
protected set
|
||||
@ -81,7 +50,5 @@ namespace Aurora.Backend.Models
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
17
Aurora/Backend/Models/Media/BaseMetadata.cs
Normal file
17
Aurora/Backend/Models/Media/BaseMetadata.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
namespace Aurora.Backend.Models.Media
|
||||
{
|
||||
public class BaseMetadata
|
||||
{
|
||||
public BaseMetadata()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extra data associated with a song.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public object ExtraData { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -1,18 +1,26 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Aurora.Backend.Models
|
||||
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 AudioMetadata Metadata { get; private set; }
|
||||
|
||||
public override MediaTypeEnum MediaType
|
||||
{
|
||||
get { return MediaTypeEnum.Audio; }
|
||||
}
|
||||
|
||||
#endregion Properties
|
||||
|
||||
/// <summary>
|
||||
@ -41,5 +49,18 @@ namespace Aurora.Backend.Models
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
9
Aurora/Backend/Models/Media/MediaTypeEnum.cs
Normal file
9
Aurora/Backend/Models/Media/MediaTypeEnum.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
namespace Aurora.Backend.Models.Media
|
||||
{
|
||||
public enum MediaTypeEnum
|
||||
{
|
||||
Audio,
|
||||
Video,
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using Aurora.Backend.Models;
|
||||
using Aurora.Backend.Models.Media;
|
||||
using Aurora.Backend.Utils;
|
||||
|
||||
namespace Aurora.Backend.Services
|
||||
@ -14,7 +14,6 @@ namespace Aurora.Backend.Services
|
||||
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
|
||||
private Dictionary<string, BaseMedia> _library;
|
||||
|
||||
|
||||
#endregion Fields
|
||||
|
||||
public LibraryService()
|
||||
@ -50,13 +49,7 @@ namespace Aurora.Backend.Services
|
||||
{
|
||||
TagLib.File tagFile = TagLib.File.Create(file.FullName);
|
||||
|
||||
BaseMedia song = new LocalAudio(file)
|
||||
{
|
||||
Title = tagFile.Tag.Title,
|
||||
Album = tagFile.Tag.Album,
|
||||
Artist = tagFile.Tag.FirstAlbumArtist
|
||||
};
|
||||
|
||||
BaseMedia song = new LocalAudio(file);
|
||||
_library.Add(song.Id, song);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using Aurora.Backend.Models;
|
||||
using Aurora.Backend.Models.Media;
|
||||
using LibVLCSharp.Shared;
|
||||
|
||||
namespace Aurora.Backend.Services.PlayerService
|
||||
@ -54,10 +54,10 @@ namespace Aurora.Backend.Services.PlayerService
|
||||
/// </summary>
|
||||
public void Play()
|
||||
{
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Playing));
|
||||
PlaybackState oldState = _state;
|
||||
_state = PlaybackState.Playing;
|
||||
_mediaPlayer.Play();
|
||||
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(oldState, _state));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -65,9 +65,10 @@ namespace Aurora.Backend.Services.PlayerService
|
||||
/// </summary>
|
||||
public void Pause()
|
||||
{
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Buffering));
|
||||
PlaybackState oldState = _state;
|
||||
_state = PlaybackState.Buffering;
|
||||
_mediaPlayer.Pause();
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(oldState, _state));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -75,9 +76,10 @@ namespace Aurora.Backend.Services.PlayerService
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Stopped));
|
||||
PlaybackState oldState = _state;
|
||||
_state = PlaybackState.Stopped;
|
||||
_mediaPlayer.Stop();
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(oldState, _state));
|
||||
}
|
||||
|
||||
public void Enqueue(BaseMedia song)
|
||||
|
Reference in New Issue
Block a user