diff --git a/.vscode/launch.json b/.vscode/launch.json
index 8a67338..600453d 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -10,7 +10,7 @@
"type": "mono",
"request": "attach",
"address": "localhost",
- "port": 55555
+ "port": 55555,
}
]
}
\ No newline at end of file
diff --git a/Aurora/Backend/Models/BaseSong.cs b/Aurora/Backend/Models/BaseMedia.cs
similarity index 96%
rename from Aurora/Backend/Models/BaseSong.cs
rename to Aurora/Backend/Models/BaseMedia.cs
index 935029a..1175bc6 100644
--- a/Aurora/Backend/Models/BaseSong.cs
+++ b/Aurora/Backend/Models/BaseMedia.cs
@@ -3,12 +3,12 @@ using System.IO;
namespace Aurora.Backend.Models
{
- public abstract class BaseSong
+ public abstract class BaseMedia
{
private bool _loaded;
private Stream _stream;
- public BaseSong()
+ public BaseMedia()
{
_loaded = false;
Id = Guid.NewGuid().ToString();
diff --git a/Aurora/Backend/Models/LocalSong.cs b/Aurora/Backend/Models/LocalAudio.cs
similarity index 75%
rename from Aurora/Backend/Models/LocalSong.cs
rename to Aurora/Backend/Models/LocalAudio.cs
index 502344c..4198e0f 100644
--- a/Aurora/Backend/Models/LocalSong.cs
+++ b/Aurora/Backend/Models/LocalAudio.cs
@@ -3,9 +3,9 @@ using System.IO;
namespace Aurora.Backend.Models
{
- public class LocalSong : BaseSong
+ public class LocalAudio : BaseMedia
{
- public LocalSong(FileInfo fileInfo)
+ public LocalAudio(FileInfo fileInfo)
{
File = fileInfo;
}
@@ -15,6 +15,9 @@ namespace Aurora.Backend.Models
#endregion Properties
+ ///
+ /// Override load method.
+ ///
public override void Load()
{
if (this.DataStream != null)
@@ -26,6 +29,9 @@ namespace Aurora.Backend.Models
base.Load();
}
+ ///
+ /// Override unload method
+ ///
public override void Unload()
{
if (this.DataStream != null)
diff --git a/Aurora/Backend/Services/LibraryService.cs b/Aurora/Backend/Services/LibraryService.cs
index 1d56f67..dbdbd95 100644
--- a/Aurora/Backend/Services/LibraryService.cs
+++ b/Aurora/Backend/Services/LibraryService.cs
@@ -12,14 +12,14 @@ namespace Aurora.Backend.Services
#region Fields
private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music";
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
- private Dictionary _library;
+ private Dictionary _library;
#endregion Fields
public LibraryService()
{
- _library = new Dictionary();
+ _library = new Dictionary();
LoadLibrary();
}
@@ -27,10 +27,10 @@ namespace Aurora.Backend.Services
/// Gets the songs.
///
/// The songs.
- public ObservableCollection GetLibrary()
+ public ObservableCollection GetLibrary()
{
- ObservableCollection collection = new ObservableCollection();
- foreach (KeyValuePair pair in _library)
+ ObservableCollection collection = new ObservableCollection();
+ foreach (KeyValuePair pair in _library)
{
collection.Add(pair.Value);
}
@@ -50,7 +50,7 @@ namespace Aurora.Backend.Services
{
TagLib.File tagFile = TagLib.File.Create(file.FullName);
- BaseSong song = new LocalSong(file)
+ BaseMedia song = new LocalAudio(file)
{
Title = tagFile.Tag.Title,
Album = tagFile.Tag.Album,
diff --git a/Aurora/Backend/Services/PlayerService.cs b/Aurora/Backend/Services/PlayerService.cs
deleted file mode 100644
index 8958158..0000000
--- a/Aurora/Backend/Services/PlayerService.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using System;
-using Aurora.Backend.Models;
-using LibVLCSharp.Shared;
-
-namespace Aurora.Backend.Services
-{
- public class PlayerService : BaseService
- {
- public PlayerService()
- {
- }
-
- public void Play(BaseSong song)
- {
- using (var libVLC = new LibVLC())
- {
- song.Load();
- var media = new Media(libVLC, song.DataStream);
- using (var mp = new MediaPlayer(media))
- {
- media.Dispose();
- mp.Play();
- Console.ReadKey();
- }
-
- song.Unload();
- }
-
-
- }
-
- }
-}
diff --git a/Aurora/Backend/Services/PlayerService/PlaybackState.cs b/Aurora/Backend/Services/PlayerService/PlaybackState.cs
new file mode 100644
index 0000000..37c6773
--- /dev/null
+++ b/Aurora/Backend/Services/PlayerService/PlaybackState.cs
@@ -0,0 +1,9 @@
+using System;
+
+public enum PlaybackState
+{
+ Playing,
+ Stopped,
+ Buffering,
+
+}
\ No newline at end of file
diff --git a/Aurora/Backend/Services/PlayerService/PlaybackStateChangedEvent.cs b/Aurora/Backend/Services/PlayerService/PlaybackStateChangedEvent.cs
new file mode 100644
index 0000000..461049a
--- /dev/null
+++ b/Aurora/Backend/Services/PlayerService/PlaybackStateChangedEvent.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace Aurora.Backend.Services.PlayerService
+{
+ public delegate void PlaybackStateChangedEventHandler(object source, PlaybackStateChangedEventArgs e);
+
+ public class PlaybackStateChangedEventArgs : EventArgs
+ {
+ public PlaybackState OldState { get; }
+ public PlaybackState NewState { get; }
+
+ public PlaybackStateChangedEventArgs(PlaybackState oldState, PlaybackState newState)
+ {
+ OldState = oldState;
+ NewState = newState;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Aurora/Backend/Services/PlayerService/PlayerService.cs b/Aurora/Backend/Services/PlayerService/PlayerService.cs
new file mode 100644
index 0000000..c92cd87
--- /dev/null
+++ b/Aurora/Backend/Services/PlayerService/PlayerService.cs
@@ -0,0 +1,116 @@
+using System;
+using Aurora.Backend.Models;
+using LibVLCSharp.Shared;
+
+namespace Aurora.Backend.Services.PlayerService
+{
+ public class PlayerService : BaseService
+ {
+ private BaseMedia _currentMedia;
+ private MediaPlayer _mediaPlayer;
+ private LibVLC _libvlc;
+ private PlaybackState _state;
+
+ public PlayerService()
+ {
+ _libvlc = new LibVLC();
+ _state = PlaybackState.Stopped;
+ }
+
+ ///
+ /// Event handler for changing playback states.
+ ///
+ public event PlaybackStateChangedEventHandler PlaybackStateChanged;
+
+ ///
+ /// The state of playback
+ ///
+ ///
+ public PlaybackState PlaybackState
+ {
+ get { return _state; }
+ }
+
+ ///
+ /// Load media into the media player.
+ ///
+ /// Media to load
+ public void LoadMedia(BaseMedia media)
+ {
+ if (_state == PlaybackState.Playing || _state == PlaybackState.Buffering)
+ {
+ Unload();
+ }
+ _currentMedia = media;
+ _currentMedia.Load();
+ var md = new Media(_libvlc, _currentMedia.DataStream);
+ _mediaPlayer = new MediaPlayer(md);
+ _mediaPlayer.Stopped += OnStopped;
+ md.Dispose();
+ }
+
+ ///
+ /// Play currently loaded media.
+ ///
+ public void Play()
+ {
+ PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Playing));
+ _state = PlaybackState.Playing;
+ _mediaPlayer.Play();
+
+ }
+
+ ///
+ /// Pause currently loaded media.
+ ///
+ public void Pause()
+ {
+ PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Buffering));
+ _state = PlaybackState.Buffering;
+ _mediaPlayer.Pause();
+ }
+
+ ///
+ /// Stop currently loaded media.
+ ///
+ public void Stop()
+ {
+ PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Stopped));
+ _state = PlaybackState.Stopped;
+ _mediaPlayer.Stop();
+ }
+
+ public void Enqueue(BaseMedia song)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void Dequeue(BaseMedia song)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Unload currently loaded media.
+ ///
+ private void Unload()
+ {
+ _currentMedia.Unload();
+ _mediaPlayer.Media = null;
+ _mediaPlayer = null;
+ }
+
+ ///
+ /// Event fired when currently loaded media player stops.
+ ///
+ ///
+ ///
+ private void OnStopped(object sender, EventArgs args)
+ {
+ PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Stopped));
+ _state = PlaybackState.Stopped;
+ this.Unload();
+ }
+
+ }
+}
diff --git a/Aurora/Frontend/Components/MediaPlayer/Player.xaml b/Aurora/Frontend/Components/MediaPlayer/Player.xaml
new file mode 100644
index 0000000..f242330
--- /dev/null
+++ b/Aurora/Frontend/Components/MediaPlayer/Player.xaml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs b/Aurora/Frontend/Components/MediaPlayer/Player.xaml.cs
similarity index 67%
rename from Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs
rename to Aurora/Frontend/Components/MediaPlayer/Player.xaml.cs
index a706029..aa70bdf 100644
--- a/Aurora/Frontend/Components/MusicPlayer/Player.xaml.cs
+++ b/Aurora/Frontend/Components/MediaPlayer/Player.xaml.cs
@@ -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();
}
}
diff --git a/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs b/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
new file mode 100644
index 0000000..b511545
--- /dev/null
+++ b/Aurora/Frontend/Components/MediaPlayer/PlayerViewModel.cs
@@ -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
+ }
+}
diff --git a/Aurora/Frontend/Components/MusicPlayer/Player.xaml b/Aurora/Frontend/Components/MusicPlayer/Player.xaml
deleted file mode 100644
index 3df65c5..0000000
--- a/Aurora/Frontend/Components/MusicPlayer/Player.xaml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/Aurora/Frontend/Views/Albums/AlbumsView.xaml b/Aurora/Frontend/Views/Albums/AlbumsView.xaml
index 3ac2daf..284ef2a 100644
--- a/Aurora/Frontend/Views/Albums/AlbumsView.xaml
+++ b/Aurora/Frontend/Views/Albums/AlbumsView.xaml
@@ -1,6 +1,6 @@
-
+
-
+
diff --git a/Aurora/Frontend/Views/Albums/AlbumsView.xaml.cs b/Aurora/Frontend/Views/Albums/AlbumsView.xaml.cs
index 9da7656..c94ed87 100644
--- a/Aurora/Frontend/Views/Albums/AlbumsView.xaml.cs
+++ b/Aurora/Frontend/Views/Albums/AlbumsView.xaml.cs
@@ -5,7 +5,7 @@ using Xamarin.Forms;
namespace Aurora.Frontend.Views.Albums
{
- public partial class AlbumsView : ContentPage
+ public partial class AlbumsView : ContentView
{
public AlbumsView()
{
diff --git a/Aurora/Frontend/Views/Artists/ArtistsView.xaml b/Aurora/Frontend/Views/Artists/ArtistsView.xaml
index aa817a7..ec87834 100644
--- a/Aurora/Frontend/Views/Artists/ArtistsView.xaml
+++ b/Aurora/Frontend/Views/Artists/ArtistsView.xaml
@@ -1,5 +1,5 @@
-
+
-
+
diff --git a/Aurora/Frontend/Views/Artists/ArtistsView.xaml.cs b/Aurora/Frontend/Views/Artists/ArtistsView.xaml.cs
index bd520a5..93d2bc3 100644
--- a/Aurora/Frontend/Views/Artists/ArtistsView.xaml.cs
+++ b/Aurora/Frontend/Views/Artists/ArtistsView.xaml.cs
@@ -5,7 +5,7 @@ using Xamarin.Forms;
namespace Aurora.Frontend.Views.Artists
{
- public partial class ArtistsView : ContentPage
+ public partial class ArtistsView : ContentView
{
public ArtistsView()
{
diff --git a/Aurora/Frontend/Views/MainView/MainView.xaml b/Aurora/Frontend/Views/MainView/MainView.xaml
index 0096f56..a91b75e 100644
--- a/Aurora/Frontend/Views/MainView/MainView.xaml
+++ b/Aurora/Frontend/Views/MainView/MainView.xaml
@@ -1,21 +1,21 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Aurora/Frontend/Views/MainView/MainView.xaml.cs b/Aurora/Frontend/Views/MainView/MainView.xaml.cs
index 309a97a..5be711d 100644
--- a/Aurora/Frontend/Views/MainView/MainView.xaml.cs
+++ b/Aurora/Frontend/Views/MainView/MainView.xaml.cs
@@ -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 screenList = (ObservableCollection)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;
}
diff --git a/Aurora/Frontend/Views/MainView/PageContainer.xaml b/Aurora/Frontend/Views/MainView/PageContainer.xaml
new file mode 100644
index 0000000..5f95fb4
--- /dev/null
+++ b/Aurora/Frontend/Views/MainView/PageContainer.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Aurora/Frontend/Views/MainView/PageContainer.xaml.cs b/Aurora/Frontend/Views/MainView/PageContainer.xaml.cs
new file mode 100644
index 0000000..735a905
--- /dev/null
+++ b/Aurora/Frontend/Views/MainView/PageContainer.xaml.cs
@@ -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();
+ }
+ }
+}
diff --git a/Aurora/Frontend/Views/Songs/SongsView.xaml b/Aurora/Frontend/Views/Songs/SongsView.xaml
index ee475b6..a3b2370 100644
--- a/Aurora/Frontend/Views/Songs/SongsView.xaml
+++ b/Aurora/Frontend/Views/Songs/SongsView.xaml
@@ -1,5 +1,5 @@
-
-
+
diff --git a/Aurora/Frontend/Views/Songs/SongsView.xaml.cs b/Aurora/Frontend/Views/Songs/SongsView.xaml.cs
index 24e46e8..973fe5a 100644
--- a/Aurora/Frontend/Views/Songs/SongsView.xaml.cs
+++ b/Aurora/Frontend/Views/Songs/SongsView.xaml.cs
@@ -5,7 +5,7 @@ using Xamarin.Forms;
namespace Aurora.Frontend.Views.Songs
{
- public partial class SongsView : ContentPage
+ public partial class SongsView : ContentView
{
public SongsView()
{
diff --git a/Aurora/Frontend/Views/Songs/SongsViewModel.cs b/Aurora/Frontend/Views/Songs/SongsViewModel.cs
index 0105807..4e436ba 100644
--- a/Aurora/Frontend/Views/Songs/SongsViewModel.cs
+++ b/Aurora/Frontend/Views/Songs/SongsViewModel.cs
@@ -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 _songsList;
- private BaseSong _selectedSong;
+ private ObservableCollection _songsList;
+ private BaseMedia _selectedSong;
#endregion Fields
#region Constructor
public SongsViewModel()
{
- _songsList = new ObservableCollection();
+ _songsList = new ObservableCollection();
PlayCommand = new Command(PlayExecute);
Initialize();
}
@@ -24,13 +25,13 @@ namespace Aurora.Frontend.Views.Songs
#endregion Constructor
#region Properties
- public ObservableCollection SongsList
+ public ObservableCollection 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
diff --git a/Aurora/Frontend/Views/Stations/StationsViewModel.xaml b/Aurora/Frontend/Views/Stations/StationsViewModel.xaml
index b89c794..8909877 100644
--- a/Aurora/Frontend/Views/Stations/StationsViewModel.xaml
+++ b/Aurora/Frontend/Views/Stations/StationsViewModel.xaml
@@ -1,5 +1,5 @@
-
+
-
+
\ No newline at end of file
diff --git a/Aurora/Frontend/Views/Stations/StationsViewModel.xaml.cs b/Aurora/Frontend/Views/Stations/StationsViewModel.xaml.cs
index d9a76de..8827397 100644
--- a/Aurora/Frontend/Views/Stations/StationsViewModel.xaml.cs
+++ b/Aurora/Frontend/Views/Stations/StationsViewModel.xaml.cs
@@ -5,7 +5,7 @@ using Xamarin.Forms;
namespace Aurora.Frontend.Views.Stations
{
- public partial class StationsView : ContentPage
+ public partial class StationsView : ContentView
{
public StationsView()
{
diff --git a/aurora.code-workspace b/aurora.code-workspace
index 362d7c2..c4facab 100644
--- a/aurora.code-workspace
+++ b/aurora.code-workspace
@@ -3,5 +3,12 @@
{
"path": "."
}
- ]
+ ],
+ "settings": {
+ "files.exclude": {
+ "**/bin": true,
+ "**/obj": true,
+ "**/packages": true
+ }
+ }
}
\ No newline at end of file