Reorganization
This commit is contained in:
42
Aurora/Design/Components/MediaPlayer/Player.xaml
Normal file
42
Aurora/Design/Components/MediaPlayer/Player.xaml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Aurora.Design.Components.MediaPlayer.Player">
|
||||
<ContentView.Content>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition
|
||||
Width="100"/>
|
||||
<ColumnDefinition
|
||||
Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackLayout
|
||||
Grid.Column="0">
|
||||
<Label
|
||||
Text="{Binding SongTitle}"/>
|
||||
<Label
|
||||
Text="{Binding ArtistName}"/>
|
||||
</StackLayout>
|
||||
<StackLayout
|
||||
Grid.Column="1"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
Text="Previous"
|
||||
Command="{Binding PreviousCommand}"
|
||||
WidthRequest="100"
|
||||
HeightRequest="50"/>
|
||||
<Button
|
||||
Text="{Binding PlayButtonText}"
|
||||
Command="{Binding PlayCommand}"
|
||||
WidthRequest="100"
|
||||
HeightRequest="50"/>
|
||||
<Button
|
||||
Text="Next"
|
||||
Command="{Binding NextCommand}"
|
||||
WidthRequest="100"
|
||||
HeightRequest="50"/>
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
15
Aurora/Design/Components/MediaPlayer/Player.xaml.cs
Normal file
15
Aurora/Design/Components/MediaPlayer/Player.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Design.Components.MediaPlayer
|
||||
{
|
||||
public partial class Player : ContentView
|
||||
{
|
||||
public Player()
|
||||
{
|
||||
BindingContext = new PlayerViewModel();
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
163
Aurora/Design/Components/MediaPlayer/PlayerViewModel.cs
Normal file
163
Aurora/Design/Components/MediaPlayer/PlayerViewModel.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using Xamarin.Forms;
|
||||
using Aurora.Design.Views;
|
||||
using Aurora.Services.PlayerService;
|
||||
using Aurora.Models.Media;
|
||||
|
||||
namespace Aurora.Design.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);
|
||||
NextCommand = new Command(OnNextExecute, CanNextExecute);
|
||||
}
|
||||
|
||||
~PlayerViewModel()
|
||||
{
|
||||
_playerService.PlaybackStateChanged -= OnPlaybackStateChanged;
|
||||
|
||||
}
|
||||
|
||||
#region Public Properties
|
||||
public Command PlayCommand { get; private set; }
|
||||
public Command NextCommand { get; private set; }
|
||||
public Command PreviousCommand { get; private set; }
|
||||
|
||||
public string PlayButtonText
|
||||
{
|
||||
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
|
||||
|
||||
#region Public Methods
|
||||
public bool CanPreviousExecute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public void OnPreviousExecute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool CanPlayExecute()
|
||||
{
|
||||
switch (_playerService.PlaybackState)
|
||||
{
|
||||
case PlaybackState.Buffering:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
case PlaybackState.Playing:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
case PlaybackState.Stopped:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnPlayExecute()
|
||||
{
|
||||
switch (_playerService.PlaybackState)
|
||||
{
|
||||
case PlaybackState.Buffering:
|
||||
{
|
||||
_playerService.Play();
|
||||
break;
|
||||
}
|
||||
case PlaybackState.Playing:
|
||||
{
|
||||
_playerService.Pause();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanNextExecute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnNextExecute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#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");
|
||||
PlayCommand.ChangeCanExecute();
|
||||
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