diff --git a/Aurora/Backend/Models/Media/BaseMedia.cs b/Aurora/Backend/Models/Media/BaseMedia.cs
index 97a2c27..a33b26c 100644
--- a/Aurora/Backend/Models/Media/BaseMedia.cs
+++ b/Aurora/Backend/Models/Media/BaseMedia.cs
@@ -31,6 +31,8 @@ namespace Aurora.Backend.Models.Media
public abstract MediaTypeEnum MediaType { get; }
+ public abstract BaseMetadata Metadata { get; protected set; }
+
///
/// Gets or sets the data stream that holds the song.
diff --git a/Aurora/Backend/Models/Media/LocalAudio.cs b/Aurora/Backend/Models/Media/LocalAudio.cs
index 735c43f..ed23b31 100644
--- a/Aurora/Backend/Models/Media/LocalAudio.cs
+++ b/Aurora/Backend/Models/Media/LocalAudio.cs
@@ -14,7 +14,7 @@ namespace Aurora.Backend.Models.Media
#region Properties
public FileInfo File { get; private set; }
- public AudioMetadata Metadata { get; private set; }
+ public override BaseMetadata Metadata { get; protected set; }
public override MediaTypeEnum MediaType
{
diff --git a/Aurora/Backend/Services/PlayerService/MediaChangedEvent.cs b/Aurora/Backend/Services/PlayerService/MediaChangedEvent.cs
new file mode 100644
index 0000000..d8dd542
--- /dev/null
+++ b/Aurora/Backend/Services/PlayerService/MediaChangedEvent.cs
@@ -0,0 +1,17 @@
+using System;
+using Aurora.Backend.Models.Media;
+
+namespace Aurora.Backend.Services.PlayerService
+{
+ public delegate void MediaChangedEventHandler(object source, MediaChangedEventArgs e);
+
+ public class MediaChangedEventArgs : EventArgs
+ {
+ public BaseMetadata NewMetadata { get; private set; }
+
+ public MediaChangedEventArgs(BaseMetadata metadata)
+ {
+ NewMetadata = metadata;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Aurora/Backend/Services/PlayerService/PlaybackStateChangedEvent.cs b/Aurora/Backend/Services/PlayerService/PlaybackStateChangedEvent.cs
index 461049a..a498df6 100644
--- a/Aurora/Backend/Services/PlayerService/PlaybackStateChangedEvent.cs
+++ b/Aurora/Backend/Services/PlayerService/PlaybackStateChangedEvent.cs
@@ -1,4 +1,5 @@
using System;
+using Aurora.Backend.Models.Media;
namespace Aurora.Backend.Services.PlayerService
{
diff --git a/Aurora/Backend/Services/PlayerService/PlayerService.cs b/Aurora/Backend/Services/PlayerService/PlayerService.cs
index 4fd344d..d163871 100644
--- a/Aurora/Backend/Services/PlayerService/PlayerService.cs
+++ b/Aurora/Backend/Services/PlayerService/PlayerService.cs
@@ -22,6 +22,8 @@ namespace Aurora.Backend.Services.PlayerService
///
public event PlaybackStateChangedEventHandler PlaybackStateChanged;
+ public event MediaChangedEventHandler MediaChanged;
+
///
/// The state of playback
///
@@ -47,6 +49,8 @@ namespace Aurora.Backend.Services.PlayerService
_mediaPlayer = new MediaPlayer(md);
_mediaPlayer.Stopped += OnStopped;
md.Dispose();
+
+ MediaChanged.Invoke(this, new MediaChangedEventArgs(_currentMedia.Metadata));
}
///
diff --git a/Aurora/Frontend/Components/MediaPlayer/Player.xaml b/Aurora/Frontend/Components/MediaPlayer/Player.xaml
index 1c92205..1d6a20f 100644
--- a/Aurora/Frontend/Components/MediaPlayer/Player.xaml
+++ b/Aurora/Frontend/Components/MediaPlayer/Player.xaml
@@ -14,7 +14,7 @@
+ Text="{Binding SongTitle}"/>
diff --git a/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs b/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
index b511545..0e64edb 100644
--- a/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
+++ b/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
@@ -2,16 +2,20 @@
using Xamarin.Forms;
using Aurora.Frontend.Views;
using Aurora.Backend.Services.PlayerService;
+using Aurora.Backend.Models.Media;
namespace Aurora.Frontend.Components.MediaPlayer
{
public class PlayerViewModel : BaseViewModel
{
PlayerService _playerService;
+ BaseMetadata _metadata;
+
public PlayerViewModel()
{
_playerService = PlayerService.Instance;
_playerService.PlaybackStateChanged += OnPlaybackStateChanged;
+ _playerService.MediaChanged += OnMediaChanged;
PlayCommand = new Command(OnPlayExecute, CanPlayExecute);
PreviousCommand = new Command(OnPreviousExecute, CanPreviousExecute);
@@ -20,6 +24,7 @@ namespace Aurora.Frontend.Components.MediaPlayer
~PlayerViewModel()
{
+ _playerService.PlaybackStateChanged -= OnPlaybackStateChanged;
}
@@ -28,10 +33,43 @@ namespace Aurora.Frontend.Components.MediaPlayer
public Command NextCommand { get; private set; }
public Command PreviousCommand { get; private set; }
-
public string PlayButtonText
{
- get { return PlayerService.Instance.PlaybackState == PlaybackState.Buffering ? "Play" : "Pause"; }
+ get { return _playerService.PlaybackState == PlaybackState.Buffering ? "Play" : "Pause"; }
+ }
+
+ ///
+ /// TODO keep player view generic between audio and video.
+ ///
+ ///
+ public string ArtistName
+ {
+ get
+ {
+ if (_metadata == null)
+ {
+ return "";
+ }
+ AudioMetadata metadata = _metadata as AudioMetadata;
+ return metadata.Artist;
+ }
+ }
+
+ ///
+ /// TODO keep player view generic between audio and video.
+ ///
+ ///
+ public string SongTitle
+ {
+ get
+ {
+ if (_metadata == null)
+ {
+ return "";
+ }
+ AudioMetadata metadata = _metadata as AudioMetadata;
+ return metadata.Title;
+ }
}
#endregion Public Properties
@@ -96,6 +134,11 @@ namespace Aurora.Frontend.Components.MediaPlayer
#endregion public Methods
#region EventHandlers
+ ///
+ /// PlayerService playback state changed event handler.
+ ///
+ /// The sending object.
+ /// Event arguments.
public void OnPlaybackStateChanged(object sender, PlaybackStateChangedEventArgs args)
{
OnPropertyChanged("PlayButtonText");
@@ -103,6 +146,18 @@ namespace Aurora.Frontend.Components.MediaPlayer
NextCommand.ChangeCanExecute();
PreviousCommand.ChangeCanExecute();
}
+
+ ///
+ /// PlayerService media changed event handler.
+ ///
+ /// The sending object.
+ /// Event arguments.
+ public void OnMediaChanged(object sender, MediaChangedEventArgs args)
+ {
+ _metadata = args.NewMetadata;
+ OnPropertyChanged("ArtistName");
+ OnPropertyChanged("SongTitle");
+ }
#endregion EventHandlers
}
}