From 80e9a4543d73c39f967e753627c44f238e2d90e6 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Fri, 24 May 2019 15:59:26 -0400 Subject: [PATCH] Added base classes to encapsulate metadata in media --- Aurora/Backend/Models/Media/AudioMetadata.cs | 35 ++++++++++ .../Backend/Models/{ => Media}/BaseMedia.cs | 41 ++--------- Aurora/Backend/Models/Media/BaseMetadata.cs | 17 +++++ .../Backend/Models/{ => Media}/LocalAudio.cs | 23 +++++- Aurora/Backend/Models/Media/MediaTypeEnum.cs | 9 +++ Aurora/Backend/Services/LibraryService.cs | 11 +-- .../Services/PlayerService/PlayerService.cs | 12 ++-- .../Components/MediaPlayer/Player.xaml | 44 ++++++++++-- .../Frontend/Views/MainView/MainView.xaml.cs | 28 ++++++-- .../Views/MainView/PageContainer.xaml | 27 +++++-- Aurora/Frontend/Views/Songs/SongsView.xaml | 70 ++++++++++++------- Aurora/Frontend/Views/Songs/SongsViewModel.cs | 2 +- 12 files changed, 222 insertions(+), 97 deletions(-) create mode 100644 Aurora/Backend/Models/Media/AudioMetadata.cs rename Aurora/Backend/Models/{ => Media}/BaseMedia.cs (50%) create mode 100644 Aurora/Backend/Models/Media/BaseMetadata.cs rename Aurora/Backend/Models/{ => Media}/LocalAudio.cs (60%) create mode 100644 Aurora/Backend/Models/Media/MediaTypeEnum.cs diff --git a/Aurora/Backend/Models/Media/AudioMetadata.cs b/Aurora/Backend/Models/Media/AudioMetadata.cs new file mode 100644 index 0000000..6410c0c --- /dev/null +++ b/Aurora/Backend/Models/Media/AudioMetadata.cs @@ -0,0 +1,35 @@ +using System; + +namespace Aurora.Backend.Models.Media +{ + public class AudioMetadata : BaseMetadata + { + public void AutioMetadata() + { + } + + /// + /// The title of the song. + /// + /// + public string Title { get; set; } + + /// + /// The artist of the song. + /// + /// + public string Artist { get; set; } + + /// + /// The album from which the song belongs. + /// + /// + public string Album { get; set; } + + /// + /// The duration of the song. + /// + /// + public string Duration { get; set; } + } +} \ No newline at end of file diff --git a/Aurora/Backend/Models/BaseMedia.cs b/Aurora/Backend/Models/Media/BaseMedia.cs similarity index 50% rename from Aurora/Backend/Models/BaseMedia.cs rename to Aurora/Backend/Models/Media/BaseMedia.cs index 1175bc6..97a2c27 100644 --- a/Aurora/Backend/Models/BaseMedia.cs +++ b/Aurora/Backend/Models/Media/BaseMedia.cs @@ -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; } - /// - /// The title of the song. - /// - /// - public string Title { get; set; } - - /// - /// The artist of the song. - /// - /// - public string Artist { get; set; } - - /// - /// The album from which the song belongs. - /// - /// - public string Album { get; set; } - - /// - /// The duration of the song. - /// - /// - public string Duration { get; set; } - - /// - /// Extra data associated with a song. - /// - /// - 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; } + + /// /// Gets or sets the data stream that holds the song. /// @@ -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 } } } - } - } diff --git a/Aurora/Backend/Models/Media/BaseMetadata.cs b/Aurora/Backend/Models/Media/BaseMetadata.cs new file mode 100644 index 0000000..328cb9b --- /dev/null +++ b/Aurora/Backend/Models/Media/BaseMetadata.cs @@ -0,0 +1,17 @@ +using System; +namespace Aurora.Backend.Models.Media +{ + public class BaseMetadata + { + public BaseMetadata() + { + } + + /// + /// Extra data associated with a song. + /// + /// + public object ExtraData { get; set; } + + } +} \ No newline at end of file diff --git a/Aurora/Backend/Models/LocalAudio.cs b/Aurora/Backend/Models/Media/LocalAudio.cs similarity index 60% rename from Aurora/Backend/Models/LocalAudio.cs rename to Aurora/Backend/Models/Media/LocalAudio.cs index 4198e0f..735c43f 100644 --- a/Aurora/Backend/Models/LocalAudio.cs +++ b/Aurora/Backend/Models/Media/LocalAudio.cs @@ -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 /// @@ -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 + }; + } } } \ No newline at end of file diff --git a/Aurora/Backend/Models/Media/MediaTypeEnum.cs b/Aurora/Backend/Models/Media/MediaTypeEnum.cs new file mode 100644 index 0000000..10cfc65 --- /dev/null +++ b/Aurora/Backend/Models/Media/MediaTypeEnum.cs @@ -0,0 +1,9 @@ +using System; +namespace Aurora.Backend.Models.Media +{ + public enum MediaTypeEnum + { + Audio, + Video, + } +} \ No newline at end of file diff --git a/Aurora/Backend/Services/LibraryService.cs b/Aurora/Backend/Services/LibraryService.cs index dbdbd95..30a03eb 100644 --- a/Aurora/Backend/Services/LibraryService.cs +++ b/Aurora/Backend/Services/LibraryService.cs @@ -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 _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); } } diff --git a/Aurora/Backend/Services/PlayerService/PlayerService.cs b/Aurora/Backend/Services/PlayerService/PlayerService.cs index c92cd87..4fd344d 100644 --- a/Aurora/Backend/Services/PlayerService/PlayerService.cs +++ b/Aurora/Backend/Services/PlayerService/PlayerService.cs @@ -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 /// 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)); } /// @@ -65,9 +65,10 @@ namespace Aurora.Backend.Services.PlayerService /// 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)); } /// @@ -75,9 +76,10 @@ namespace Aurora.Backend.Services.PlayerService /// 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) diff --git a/Aurora/Frontend/Components/MediaPlayer/Player.xaml b/Aurora/Frontend/Components/MediaPlayer/Player.xaml index f242330..1c92205 100644 --- a/Aurora/Frontend/Components/MediaPlayer/Player.xaml +++ b/Aurora/Frontend/Components/MediaPlayer/Player.xaml @@ -1,10 +1,42 @@ - + - -