See commit description for changes
Added PageContainer to dynamically load pages within the main content. Added player component to control music playback(Half functional). Added playback changed event not the player service.
This commit is contained in:
10
Aurora/Frontend/Components/MediaPlayer/Player.xaml
Normal file
10
Aurora/Frontend/Components/MediaPlayer/Player.xaml
Normal file
@ -0,0 +1,10 @@
|
||||
<?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.Frontend.Components.MediaPlayer.Player">
|
||||
<ContentView.Content>
|
||||
<StackLayout 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>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
@ -2,12 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Frontend.Components.MusicPlayer
|
||||
namespace Aurora.Frontend.Components.MediaPlayer
|
||||
{
|
||||
public partial class Player : ContentView
|
||||
{
|
||||
public Player()
|
||||
{
|
||||
BindingContext = new PlayerViewModel();
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
108
Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
Normal file
108
Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using Xamarin.Forms;
|
||||
using Aurora.Frontend.Views;
|
||||
using Aurora.Backend.Services.PlayerService;
|
||||
|
||||
namespace Aurora.Frontend.Components.MediaPlayer
|
||||
{
|
||||
public class PlayerViewModel : BaseViewModel
|
||||
{
|
||||
PlayerService _playerService;
|
||||
public PlayerViewModel()
|
||||
{
|
||||
_playerService = PlayerService.Instance;
|
||||
_playerService.PlaybackStateChanged += OnPlaybackStateChanged;
|
||||
|
||||
PlayCommand = new Command(OnPlayExecute, CanPlayExecute);
|
||||
PreviousCommand = new Command(OnPreviousExecute, CanPreviousExecute);
|
||||
NextCommand = new Command(OnNextExecute, CanNextExecute);
|
||||
}
|
||||
|
||||
~PlayerViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#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.Instance.PlaybackState == PlaybackState.Buffering ? "Play" : "Pause"; }
|
||||
}
|
||||
|
||||
#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
|
||||
public void OnPlaybackStateChanged(object sender, PlaybackStateChangedEventArgs args)
|
||||
{
|
||||
OnPropertyChanged("PlayButtonText");
|
||||
PlayCommand.ChangeCanExecute();
|
||||
NextCommand.ChangeCanExecute();
|
||||
PreviousCommand.ChangeCanExecute();
|
||||
}
|
||||
#endregion EventHandlers
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
<?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.Frontend.Components.MusicPlayer.Player">
|
||||
<ContentView.Content>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Albums.AlbumsView">
|
||||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Albums.AlbumsView">
|
||||
<ContentPage.Content>
|
||||
<Label Text="Albums" />
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
</ContentView>
|
||||
|
@ -5,7 +5,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Frontend.Views.Albums
|
||||
{
|
||||
public partial class AlbumsView : ContentPage
|
||||
public partial class AlbumsView : ContentView
|
||||
{
|
||||
public AlbumsView()
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Artists.ArtistsView">
|
||||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Artists.ArtistsView">
|
||||
<ContentPage.Content>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
</ContentView>
|
||||
|
@ -5,7 +5,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Frontend.Views.Artists
|
||||
{
|
||||
public partial class ArtistsView : ContentPage
|
||||
public partial class ArtistsView : ContentView
|
||||
{
|
||||
public ArtistsView()
|
||||
{
|
||||
|
@ -1,21 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:views="clr-namespace:Aurora.Frontend.Views.Songs"
|
||||
xmlns:views="clr-namespace:Aurora.Frontend.Views.MainView"
|
||||
xmlns:navigation="clr-namespace:Aurora.Frontend.Components.NavigationMenu"
|
||||
x:Class="Aurora.Frontend.Views.Main.MainView"
|
||||
MasterBehavior="Split">
|
||||
|
||||
<MasterDetailPage.Master>
|
||||
<navigation:NavigationMenu x:Name="MasterPage" Items="{Binding Pages}"/>
|
||||
</MasterDetailPage.Master>
|
||||
|
||||
<MasterDetailPage.Detail>
|
||||
<NavigationPage>
|
||||
<x:Arguments>
|
||||
<views:SongsView />
|
||||
</x:Arguments>
|
||||
</NavigationPage>
|
||||
</MasterDetailPage.Detail>
|
||||
<MasterDetailPage.Master>
|
||||
<navigation:NavigationMenu x:Name="MasterPage" Items="{Binding Pages}"/>
|
||||
</MasterDetailPage.Master>
|
||||
|
||||
<MasterDetailPage.Detail>
|
||||
<NavigationPage>
|
||||
<x:Arguments>
|
||||
<views:PageContainer x:Name="ContentPage" />
|
||||
</x:Arguments>
|
||||
</NavigationPage>
|
||||
</MasterDetailPage.Detail>
|
||||
|
||||
</MasterDetailPage>
|
@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Aurora.Frontend.Components.NavigationMenu;
|
||||
using Aurora.Frontend.Views.MainView;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Aurora.Frontend.Views.Main
|
||||
{
|
||||
{
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
public partial class MainView : MasterDetailPage
|
||||
{
|
||||
@ -15,6 +16,13 @@ namespace Aurora.Frontend.Views.Main
|
||||
InitializeComponent();
|
||||
BindingContext = new MainViewModel();
|
||||
MasterPage.ListView.ItemSelected += ListView_ItemSelected;
|
||||
|
||||
//Set initial view from first item in list
|
||||
ObservableCollection<NavigationGroupItem> screenList = (ObservableCollection<NavigationGroupItem>)MasterPage.ListView.ItemsSource;
|
||||
var view = (View)Activator.CreateInstance(screenList.FirstOrDefault().FirstOrDefault().TargetType);
|
||||
|
||||
ContentPresenter viewContent = (ContentPresenter)ContentPage.Content.FindByName("ViewContent");
|
||||
viewContent.Content = view;
|
||||
}
|
||||
|
||||
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
|
||||
@ -23,10 +31,10 @@ namespace Aurora.Frontend.Views.Main
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
var page = (Page)Activator.CreateInstance(item.TargetType);
|
||||
page.Title = item.Title;
|
||||
var view = (View)Activator.CreateInstance(item.TargetType);
|
||||
|
||||
Detail = new NavigationPage(page);
|
||||
ContentPresenter viewContent = (ContentPresenter)ContentPage.Content.FindByName("ViewContent");
|
||||
viewContent.Content = view;
|
||||
|
||||
MasterPage.ListView.SelectedItem = null;
|
||||
}
|
||||
|
9
Aurora/Frontend/Views/MainView/PageContainer.xaml
Normal file
9
Aurora/Frontend/Views/MainView/PageContainer.xaml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:components="clr-namespace:Aurora.Frontend.Components" xmlns:mp="clr-namespace:Aurora.Frontend.Components.MediaPlayer" x:Class="Aurora.Frontend.Views.MainView.PageContainer">
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
<ContentPresenter x:Name="ViewContent"/>
|
||||
<mp:Player HorizontalOptions="CenterAndExpand" VerticalOptions="End" HeightRequest="200"/>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
15
Aurora/Frontend/Views/MainView/PageContainer.xaml.cs
Normal file
15
Aurora/Frontend/Views/MainView/PageContainer.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Frontend.Views.MainView
|
||||
{
|
||||
public partial class PageContainer : ContentPage
|
||||
{
|
||||
public PageContainer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:songs="clr-namespace:Aurora.Frontend.Views.Songs"
|
||||
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
|
||||
@ -47,4 +47,4 @@
|
||||
|
||||
</dg:DataGrid>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
</ContentView>
|
||||
|
@ -5,7 +5,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Frontend.Views.Songs
|
||||
{
|
||||
public partial class SongsView : ContentPage
|
||||
public partial class SongsView : ContentView
|
||||
{
|
||||
public SongsView()
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using Aurora.Backend.Models;
|
||||
using Aurora.Backend.Services;
|
||||
using Aurora.Backend.Services.PlayerService;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Frontend.Views.Songs
|
||||
@ -8,15 +9,15 @@ namespace Aurora.Frontend.Views.Songs
|
||||
public class SongsViewModel : BaseViewModel
|
||||
{
|
||||
#region Fields
|
||||
private ObservableCollection<BaseSong> _songsList;
|
||||
private BaseSong _selectedSong;
|
||||
private ObservableCollection<BaseMedia> _songsList;
|
||||
private BaseMedia _selectedSong;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Constructor
|
||||
public SongsViewModel()
|
||||
{
|
||||
_songsList = new ObservableCollection<BaseSong>();
|
||||
_songsList = new ObservableCollection<BaseMedia>();
|
||||
PlayCommand = new Command(PlayExecute);
|
||||
Initialize();
|
||||
}
|
||||
@ -24,13 +25,13 @@ namespace Aurora.Frontend.Views.Songs
|
||||
#endregion Constructor
|
||||
|
||||
#region Properties
|
||||
public ObservableCollection<BaseSong> SongsList
|
||||
public ObservableCollection<BaseMedia> SongsList
|
||||
{
|
||||
get { return _songsList; }
|
||||
set { SetProperty(ref _songsList, value); }
|
||||
}
|
||||
|
||||
public BaseSong SelectedSong
|
||||
public BaseMedia SelectedSong
|
||||
{
|
||||
get { return _selectedSong; }
|
||||
set { SetProperty(ref _selectedSong, value); }
|
||||
@ -49,7 +50,8 @@ namespace Aurora.Frontend.Views.Songs
|
||||
|
||||
public void PlayExecute()
|
||||
{
|
||||
PlayerService.Instance.Play(_selectedSong);
|
||||
PlayerService.Instance.LoadMedia(_selectedSong);
|
||||
PlayerService.Instance.Play();
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Stations.StationsView">
|
||||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Frontend.Views.Stations.StationsView">
|
||||
<ContentPage.Content>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
||||
</ContentView>
|
@ -5,7 +5,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Aurora.Frontend.Views.Stations
|
||||
{
|
||||
public partial class StationsView : ContentPage
|
||||
public partial class StationsView : ContentView
|
||||
{
|
||||
public StationsView()
|
||||
{
|
||||
|
Reference in New Issue
Block a user