MediaChangedEvent now hooked up to player component.
This commit is contained in:
parent
80e9a4543d
commit
64c2285817
@ -31,6 +31,8 @@ namespace Aurora.Backend.Models.Media
|
||||
|
||||
public abstract MediaTypeEnum MediaType { get; }
|
||||
|
||||
public abstract BaseMetadata Metadata { get; protected set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data stream that holds the song.
|
||||
|
@ -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
|
||||
{
|
||||
|
17
Aurora/Backend/Services/PlayerService/MediaChangedEvent.cs
Normal file
17
Aurora/Backend/Services/PlayerService/MediaChangedEvent.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Aurora.Backend.Models.Media;
|
||||
|
||||
namespace Aurora.Backend.Services.PlayerService
|
||||
{
|
||||
|
@ -22,6 +22,8 @@ namespace Aurora.Backend.Services.PlayerService
|
||||
/// </summary>
|
||||
public event PlaybackStateChangedEventHandler PlaybackStateChanged;
|
||||
|
||||
public event MediaChangedEventHandler MediaChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The state of playback
|
||||
/// </summary>
|
||||
@ -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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -14,7 +14,7 @@
|
||||
<StackLayout
|
||||
Grid.Column="0">
|
||||
<Label
|
||||
Text="{Binding SongName}"/>
|
||||
Text="{Binding SongTitle}"/>
|
||||
<Label
|
||||
Text="{Binding ArtistName}"/>
|
||||
</StackLayout>
|
||||
|
@ -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"; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO keep player view generic between audio and video.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string ArtistName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_metadata == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
AudioMetadata metadata = _metadata as AudioMetadata;
|
||||
return metadata.Artist;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO keep player view generic between audio and video.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
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
|
||||
/// <summary>
|
||||
/// PlayerService playback state changed event handler.
|
||||
/// </summary>
|
||||
/// <param name="sender">The sending object.</param>
|
||||
/// <param name="args">Event arguments.</param>
|
||||
public void OnPlaybackStateChanged(object sender, PlaybackStateChangedEventArgs args)
|
||||
{
|
||||
OnPropertyChanged("PlayButtonText");
|
||||
@ -103,6 +146,18 @@ namespace Aurora.Frontend.Components.MediaPlayer
|
||||
NextCommand.ChangeCanExecute();
|
||||
PreviousCommand.ChangeCanExecute();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PlayerService media changed event handler.
|
||||
/// </summary>
|
||||
/// <param name="sender">The sending object.</param>
|
||||
/// <param name="args">Event arguments.</param>
|
||||
public void OnMediaChanged(object sender, MediaChangedEventArgs args)
|
||||
{
|
||||
_metadata = args.NewMetadata;
|
||||
OnPropertyChanged("ArtistName");
|
||||
OnPropertyChanged("SongTitle");
|
||||
}
|
||||
#endregion EventHandlers
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user