diff --git a/Sources/Linaris/AlbumPage.xaml b/Sources/Linaris/AlbumPage.xaml
index 360ae6f..8c19412 100644
--- a/Sources/Linaris/AlbumPage.xaml
+++ b/Sources/Linaris/AlbumPage.xaml
@@ -57,7 +57,7 @@
-
+
diff --git a/Sources/Linaris/AlbumPage.xaml.cs b/Sources/Linaris/AlbumPage.xaml.cs
index b50dd43..66b931f 100644
--- a/Sources/Linaris/AlbumPage.xaml.cs
+++ b/Sources/Linaris/AlbumPage.xaml.cs
@@ -1,3 +1,4 @@
+using CommunityToolkit.Maui.Views;
using Model;
namespace Linaris;
@@ -20,7 +21,8 @@ public partial class AlbumPage : ContentPage
InitializeComponent();
album = (Application.Current as App).Manager.CurrentAlbum;
BindingContext = album;
- }
+
+ }
private async void GoToInfoTitle(object sender, EventArgs e)
{
@@ -30,4 +32,15 @@ public partial class AlbumPage : ContentPage
await Navigation.PushAsync(new InfoTitlePage());
}
}
+
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ musicElement.Stop();
+ }
+ }
}
\ No newline at end of file
diff --git a/Sources/Linaris/FooterPage.xaml b/Sources/Linaris/FooterPage.xaml
index 316c6ba..38bd297 100644
--- a/Sources/Linaris/FooterPage.xaml
+++ b/Sources/Linaris/FooterPage.xaml
@@ -2,15 +2,16 @@
-
+
-
-
+
+
diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs
index 17ca4a5..49d2407 100644
--- a/Sources/Linaris/FooterPage.xaml.cs
+++ b/Sources/Linaris/FooterPage.xaml.cs
@@ -1,95 +1,58 @@
-using NAudio.Wave;
-using Plugin.Maui.Audio;
+using Model;
+using Model.Stub;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
namespace Linaris;
-public partial class FooterPage : ContentView
+public partial class FooterPage : ContentView, INotifyPropertyChanged
{
- public FooterPage()
- {
- InitializeComponent();
- BindingContext = (Application.Current as App).Manager;
- }
-
-
- public void RewindButton_Clicked(Object sender, EventArgs e)
- {
- /*audioFile.Position = 0;
- outputDevice?.Play();
- Play.Source = "pause.png";
- Timer_Elapsed(sender, e);
- timer = new System.Timers.Timer(1000);
- timer.Elapsed += Timer_Elapsed;
- timer.Enabled = true;*/
- }
+ private readonly Manager Manager = (Application.Current as App).Manager;
- public void NextButton_Clicked(Object sender, EventArgs e)
+ public FooterPage()
{
- /*audioFile.Position = audioFile.Length;*/
+ InitializeComponent();
+ BindingContext = Manager.CurrentPlaying;
}
- public void StopButton_Clicked(object sender, EventArgs e)
- {
- /*outputDevice.Stop();
- audioFile.Position = 0;*/
- }
- public void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
+ public void RewindButton_Clicked(object sender, EventArgs e)
{
- /*outputDevice.Volume = (float)e.NewValue;*/
+ if (Manager.CurrentPlaylist == null || Manager.CurrentPlaying == null) return;
+ Manager.PreviousTitle();
+ Dispatcher.DispatchAsync(() =>
+ {
+ music.Source = Manager.CurrentPlaying.Path;
+ });
}
- public void Bar_ValueChanged(object sender, ValueChangedEventArgs e)
+ public void NextButton_Clicked(object sender, EventArgs e)
{
- /*if (changementManuel)
+ if (Manager.CurrentPlaylist == null || Manager.CurrentPlaying == null) return;
+ Manager.NextTitle();
+ Dispatcher.DispatchAsync(() =>
{
- double totalSeconds = audioFile.TotalTime.TotalSeconds;
- double newPosition = e.NewValue * totalSeconds;
-
- audioFile.CurrentTime = TimeSpan.FromSeconds(newPosition);
- }
- else
- {
- changementManuel = true;
- }*/
+ music.Source = Manager.CurrentPlaying.Path;
+ });
}
- private void PlaybackStoppedHandler(object sender, StoppedEventArgs e)
+ public void ShuffleButton_Clicked(object sender, EventArgs e)
{
- /*if (closing)
- {
- outputDevice.Dispose();
- audioFile.Dispose();
- }
- else
- {
- Play.Dispatcher.Dispatch(() => Play.Source = "play.png");
- }*/
+ Manager.Shuffle();
}
- private void Timer_Elapsed(object sender, EventArgs e)
+ public void LoopButton_Clicked(object sender, EventArgs e)
{
- /*TimeSpan totalTimeSpan = audioFile.TotalTime;
- TimeSpan currentTimeSpan = audioFile.CurrentTime;
-
- string totalTimeFormatted = totalTimeSpan.ToString(@"hh\:mm\:ss");
- string currentTimeFormatted = currentTimeSpan.ToString(@"hh\:mm\:ss");
-
- changementManuel = false;
-
- bar.Dispatcher.Dispatch(() => bar.Value = audioFile.CurrentTime.TotalSeconds / audioFile.TotalTime.TotalSeconds);
- currentTime.Dispatcher.Dispatch(() => currentTime.Text = currentTimeFormatted);
- endTime.Dispatcher.Dispatch(() => endTime.Text = totalTimeFormatted);*/
-
+ Manager.Loop();
}
- private void LoadNewAudioFile(string filePath)
+ public void OnCompleted(object sender, EventArgs e)
{
- /*if (outputDevice.PlaybackState == PlaybackState.Playing)
+ if (Manager.CurrentPlaying == null) return;
+ Manager.NextTitle();
+ Dispatcher.DispatchAsync(() =>
{
- outputDevice.Stop();
- }
- audioFile = new AudioFileReader(filePath);
- outputDevice.Init(audioFile);*/
+ music.Source = Manager.CurrentPlaying.Path;
+ });
}
}
\ No newline at end of file
diff --git a/Sources/Linaris/InfoTitlePage.xaml b/Sources/Linaris/InfoTitlePage.xaml
index 88a5662..16c0d60 100644
--- a/Sources/Linaris/InfoTitlePage.xaml
+++ b/Sources/Linaris/InfoTitlePage.xaml
@@ -29,6 +29,6 @@
-
+
\ No newline at end of file
diff --git a/Sources/Linaris/InfoTitlePage.xaml.cs b/Sources/Linaris/InfoTitlePage.xaml.cs
index cb9d207..1eb4768 100644
--- a/Sources/Linaris/InfoTitlePage.xaml.cs
+++ b/Sources/Linaris/InfoTitlePage.xaml.cs
@@ -1,3 +1,4 @@
+using CommunityToolkit.Maui.Views;
using Model;
namespace Linaris;
@@ -25,4 +26,15 @@ public partial class InfoTitlePage : ContentPage
artist = (Application.Current as App).Manager.GetAlbumById(infoTitle.AlbumID).Artist;
BindingContext = this;
}
+
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ musicElement.Stop();
+ }
+ }
}
\ No newline at end of file
diff --git a/Sources/Linaris/Layout.xaml b/Sources/Linaris/Layout.xaml
index 855ddd1..80a927c 100644
--- a/Sources/Linaris/Layout.xaml
+++ b/Sources/Linaris/Layout.xaml
@@ -4,9 +4,9 @@
x:Class="Linaris.Layout">
-
+
-
+
\ No newline at end of file
diff --git a/Sources/Linaris/Layout.xaml.cs b/Sources/Linaris/Layout.xaml.cs
index 9cbb72b..c116bb0 100644
--- a/Sources/Linaris/Layout.xaml.cs
+++ b/Sources/Linaris/Layout.xaml.cs
@@ -1,3 +1,5 @@
+using CommunityToolkit.Maui.Views;
+
namespace Linaris;
public partial class Layout : ContentView
@@ -8,22 +10,51 @@ public partial class Layout : ContentView
}
private async void Go_Home(object sender, EventArgs e)
- {
+ {
+ StopMusic();
await Navigation.PopToRootAsync();
}
private async void Go_Playlists(object sender, EventArgs e)
- {
- await Navigation.PushAsync(new PlaylistsPage());
- }
+ {
+ StopMusic();
+ await Navigation.PushAsync(new PlaylistsPage());
+ }
private async void Go_Back(object sender, EventArgs e)
- {
- await Navigation.PopAsync();
+ {
+ StopMusic();
+ await Navigation.PopAsync();
}
private async void Go_Files(object sender, EventArgs e)
- {
+ {
+ StopMusic();
await Navigation.PushAsync(new LocalFilesPage());
}
+ private void StopMusic()
+ {
+ var parentPage = GetParentPage(this);
+ if (parentPage == null) return;
+ ContentView footer = parentPage.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ musicElement.Stop();
+ }
+ }
+
+ private ContentPage GetParentPage(Element element)
+ {
+ Element parent = element?.Parent;
+ while (parent != null)
+ {
+ if (parent is ContentPage contentPage)
+ {
+ return contentPage;
+ }
+ parent = parent.Parent;
+ }
+ return null;
+ }
}
\ No newline at end of file
diff --git a/Sources/Linaris/LocalFilesPage.xaml b/Sources/Linaris/LocalFilesPage.xaml
index f10fd12..339621f 100644
--- a/Sources/Linaris/LocalFilesPage.xaml
+++ b/Sources/Linaris/LocalFilesPage.xaml
@@ -30,9 +30,10 @@
-
-
-
+
+
+
+
@@ -59,7 +60,7 @@
-
+
diff --git a/Sources/Linaris/LocalFilesPage.xaml.cs b/Sources/Linaris/LocalFilesPage.xaml.cs
index d5c1fa4..8777e67 100644
--- a/Sources/Linaris/LocalFilesPage.xaml.cs
+++ b/Sources/Linaris/LocalFilesPage.xaml.cs
@@ -1,263 +1,274 @@
+using CommunityToolkit.Maui.Views;
using Model;
using System.Collections.ObjectModel;
-namespace Linaris
+namespace Linaris;
+
+public partial class LocalFilesPage : ContentPage
{
- public partial class LocalFilesPage : ContentPage
- {
- private ObservableCollection customTitles = (Application.Current as App).Manager.GetCustomTitles();
+ private ObservableCollection customTitles = (Application.Current as App).Manager.GetCustomTitles();
- public ObservableCollection CustomTitles
- {
- get => customTitles;
- }
+ public ObservableCollection CustomTitles
+ {
+ get => customTitles;
+ }
- private ObservableCollection playlists = (Application.Current as App).Manager.GetPlaylists();
+ private ObservableCollection playlists = (Application.Current as App).Manager.GetPlaylists();
- public ObservableCollection Playlists
- {
- get => playlists;
- }
+ public ObservableCollection Playlists
+ {
+ get => playlists;
+ }
- public LocalFilesPage()
- {
- InitializeComponent();
- BindingContext = this;
- }
+ public LocalFilesPage()
+ {
+ InitializeComponent();
+ BindingContext = this;
+ }
- // Reset methods
+ // Reset methods
- void ResetAll(object sender, EventArgs e)
- {
- ResetSubMenus(sender, e);
- }
+ void ResetAll(object sender, EventArgs e)
+ {
+ ResetSubMenus(sender, e);
+ }
- void ResetSubMenus(object sender, EventArgs e)
+ void ResetSubMenus(object sender, EventArgs e)
+ {
+ foreach (var CustomTitle in customTitles)
{
- foreach (var CustomTitle in customTitles)
- {
- CustomTitle.IsSubMenuVisible = false;
- }
- ResetPlaylistMenu(sender, e);
+ CustomTitle.IsSubMenuVisible = false;
}
-
- void ResetPlaylistMenu(object sender, EventArgs e)
+ ResetPlaylistMenu(sender, e);
+ }
+
+ void ResetPlaylistMenu(object sender, EventArgs e)
+ {
+ foreach (CustomTitle customTitle in CustomTitles)
{
- foreach (CustomTitle customTitle in CustomTitles)
- {
- customTitle.IsPlaylistMenuVisible = false;
- customTitle.IsNewPlaylistMenuVisible = false;
- }
+ customTitle.IsPlaylistMenuVisible = false;
+ customTitle.IsNewPlaylistMenuVisible = false;
}
+ }
- // Add methods
+ // Add methods
- void AddCustomTitle(CustomTitle customTitle)
- {
- (Application.Current as App).Manager.AddCustomTitle(customTitle);
- customTitles = (Application.Current as App).Manager.GetCustomTitles();
- ResetAll(this, null);
- }
+ void AddCustomTitle(CustomTitle customTitle)
+ {
+ (Application.Current as App).Manager.AddCustomTitle(customTitle);
+ customTitles = (Application.Current as App).Manager.GetCustomTitles();
+ ResetAll(this, null);
+ }
- private async void AddTitles(object sender, EventArgs e)
+ private async void AddTitles(object sender, EventArgs e)
+ {
+ var results = await FilePicker.PickMultipleAsync(new PickOptions
{
- var results = await FilePicker.PickMultipleAsync(new PickOptions
- {
- PickerTitle = "Choisissez des nouveaux titres !",
- FileTypes = new FilePickerFileType(
- new Dictionary>
- {
- { DevicePlatform.WinUI, new [] { "*.mp3", "*.m4a" } },
- { DevicePlatform.Android, new [] { "*.mp3", ".3gp", ".mp4", ".m4a", ".aac", ".ts", ".amr", ".flac", ".mid", ".xmf", ".mxmf", ".rtttl", ".rtx", ".ota", ".imy", ".mkv", ".ogg", ".wav" } },
- { DevicePlatform.iOS, new[] { "*.mp3", "*.aac", "*.aifc", "*.au", "*.aiff", "*.mp2", "*.3gp", "*.ac3" } }
- })
- });
-
- if (results == null)
- {
- return;
- }
-
- if (sender is Button button)
- {
- foreach (var result in results)
+ PickerTitle = "Choisissez des nouveaux titres !",
+ FileTypes = new FilePickerFileType(
+ new Dictionary>
{
- CustomTitle custom = new CustomTitle(result.FileName, "none.png", "", result.FullPath);
- if (!IsCustomTitleInCollection(custom))
- {
- AddCustomTitle(custom);
- }
- }
- }
- }
+ { DevicePlatform.WinUI, new [] { "*.mp3", "*.m4a" } },
+ { DevicePlatform.Android, new [] { "*.mp3", ".3gp", ".mp4", ".m4a", ".aac", ".ts", ".amr", ".flac", ".mid", ".xmf", ".mxmf", ".rtttl", ".rtx", ".ota", ".imy", ".mkv", ".ogg", ".wav" } },
+ { DevicePlatform.iOS, new[] { "*.mp3", "*.aac", "*.aifc", "*.au", "*.aiff", "*.mp2", "*.3gp", "*.ac3" } }
+ })
+ });
- string SaveIconToDataFolder(MemoryStream stream, string iconName)
+ if (results == null)
{
- string dataFolderPath = FileSystem.AppDataDirectory;
- string iconPath = Path.Combine(dataFolderPath, $"{iconName}.png");
+ return;
+ }
- using (FileStream fileStream = new FileStream(iconPath, FileMode.Create, FileAccess.Write))
+ if (sender is Button button)
+ {
+ foreach (var result in results)
{
- stream.Position = 0;
- stream.CopyTo(fileStream);
+ CustomTitle custom = new CustomTitle(result.FileName, "none.png", "", result.FullPath);
+ if (!IsCustomTitleInCollection(custom))
+ {
+ AddCustomTitle(custom);
+ }
}
-
- return iconPath;
}
+ }
- async void AddToPlaylist(object sender, EventArgs e)
+ async void AddToPlaylist(object sender, EventArgs e)
+ {
+ if (sender is Button button)
{
- if (sender is Button button)
+ if (button.BindingContext is Playlist playlist)
{
- if (button.BindingContext is Playlist playlist)
+ if (button.Parent is StackLayout stack && stack.BindingContext is CustomTitle customTitle)
{
- if (button.Parent is StackLayout stack && stack.BindingContext is CustomTitle customTitle)
+ if (playlist.HasCustomTitle(customTitle))
{
- if (playlist.HasCustomTitle(customTitle))
- {
- await DisplayAlert("Erreur !", "Ce morceau est déjà dans cette playlist !", "OK");
- return;
- }
- playlist.AddTitle(customTitle);
- ResetAll(sender, e);
+ await DisplayAlert("Erreur !", "Ce morceau est déjà dans cette playlist !", "OK");
+ return;
}
+ playlist.AddTitle(customTitle);
+ ResetAll(sender, e);
}
}
}
+ }
- void AddPlaylist(object sender, EventArgs e)
+ void AddPlaylist(object sender, EventArgs e)
+ {
+ if (sender is Entry entry)
{
- if (sender is Entry entry)
+ Playlist playlist = new Playlist(entry.Text, "", "none.png");
+ if (!IsInPlaylists(playlist))
{
- Playlist playlist = new Playlist(entry.Text, "", "none.png");
- if (!IsInPlaylists(playlist))
- {
- (Application.Current as App).Manager.AddPlaylist(playlist);
- playlists.Add(playlist);
- }
- if(entry.BindingContext is CustomTitle customTitle)
- {
- customTitle.IsNewPlaylistMenuVisible = false;
- entry.Text = "";
- }
+ (Application.Current as App).Manager.AddPlaylist(playlist);
+ playlists = (Application.Current as App).Manager.GetPlaylists();
+ }
+ if(entry.BindingContext is CustomTitle customTitle)
+ {
+ customTitle.IsNewPlaylistMenuVisible = false;
+ entry.Text = "";
}
}
+ }
- // Remove methods
+ // Remove methods
- void RemoveCustomTitle(object sender, EventArgs e)
+ void RemoveCustomTitle(object sender, EventArgs e)
+ {
+ if (sender is Button button)
{
- if (sender is Button button)
+ if (button.BindingContext is CustomTitle titleToRemove)
{
- if (button.BindingContext is CustomTitle titleToRemove)
- {
- (Application.Current as App).Manager.RemoveCustomTitle(titleToRemove);
- customTitles.Remove(titleToRemove);
- }
+ (Application.Current as App).Manager.RemoveCustomTitle(titleToRemove);
+ customTitles.Remove(titleToRemove);
}
}
+ }
- // Show methods
+ // Show methods
- void ShowSubMenu(object sender, EventArgs e)
+ void ShowSubMenu(object sender, EventArgs e)
+ {
+ if (sender is Image image)
{
- if (sender is Image image)
+ if (image.BindingContext is CustomTitle customTitle)
{
- if (image.BindingContext is CustomTitle customTitle)
+ if (!customTitle.IsSubMenuVisible)
{
- if (!customTitle.IsSubMenuVisible)
- {
- ResetAll(sender, e);
- customTitle.IsSubMenuVisible = true;
- }
- else
- {
- ResetSubMenus(sender, e);
- }
+ ResetAll(sender, e);
+ customTitle.IsSubMenuVisible = true;
+ }
+ else
+ {
+ ResetSubMenus(sender, e);
}
}
}
+ }
- void ShowPlaylistMenu(object sender, EventArgs e)
+ void ShowPlaylistMenu(object sender, EventArgs e)
+ {
+ if (sender is Button button)
{
- if (sender is Button button)
+ if (button.BindingContext is CustomTitle customTitle)
{
- if (button.BindingContext is CustomTitle customTitle)
+ if (!customTitle.IsPlaylistMenuVisible)
{
- if (!customTitle.IsPlaylistMenuVisible)
- {
- customTitle.IsPlaylistMenuVisible = true;
- }
+ customTitle.IsPlaylistMenuVisible = true;
}
}
}
+ }
- void ShowNewPlaylistMenu(object sender, EventArgs e)
+ void ShowNewPlaylistMenu(object sender, EventArgs e)
+ {
+ if (sender is Button button)
{
- if (sender is Button button)
+ if (button.BindingContext is CustomTitle customTitle)
{
- if (button.BindingContext is CustomTitle customTitle)
+ if (!customTitle.IsNewPlaylistMenuVisible)
{
- if (!customTitle.IsNewPlaylistMenuVisible)
- {
- customTitle.IsNewPlaylistMenuVisible = true;
- }
+ customTitle.IsNewPlaylistMenuVisible = true;
}
}
}
+ }
+
+ // Change methods
- // Change methods
+ private async void ChangeImage(object sender, EventArgs e)
+ {
+ var result = await FilePicker.PickAsync(new PickOptions
+ {
+ PickerTitle = "Choisissez une nouvelle image !",
+ FileTypes = FilePickerFileType.Images
+ });
- private async void ChangeImage(object sender, EventArgs e)
+ if (result == null)
{
- var result = await FilePicker.PickAsync(new PickOptions
- {
- PickerTitle = "Choisissez une nouvelle image !",
- FileTypes = FilePickerFileType.Images
- });
+ return;
+ }
- if (result == null)
+ if (sender is Button button)
+ {
+ if (button.BindingContext is CustomTitle customTitle)
{
- return;
+ customTitle.ImageURL = result.FullPath;
}
+ }
+ }
- if (sender is Button button)
+ // Search methods
+
+ bool IsCustomTitleInCollection(CustomTitle customTitle)
+ {
+ foreach(var custom in customTitles)
+ {
+ if (customTitle.Equals(custom))
{
- if (button.BindingContext is CustomTitle customTitle)
- {
- customTitle.ImageURL = result.FullPath;
- }
+ return true;
}
}
+ return false;
+ }
- // Search methods
-
- bool IsCustomTitleInCollection(CustomTitle customTitle)
+ bool IsInPlaylists(Playlist playlist)
+ {
+ foreach (Playlist p in playlists)
{
- foreach(var custom in customTitles)
+ if (p.Equals(playlist))
{
- if (customTitle.Equals(custom))
- {
- return true;
- }
+ return true;
}
- return false;
}
+ return false;
+ }
- bool IsInPlaylists(Playlist playlist)
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
{
- foreach (Playlist p in playlists)
+ musicElement.Stop();
+ }
+ }
+
+ private void Play(object sender, EventArgs e)
+ {
+ if (sender is Button button && button.BindingContext is CustomTitle customTitle)
+ {
+
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
{
- if (p.Equals(playlist))
- {
- return true;
- }
+ musicElement.Source = customTitle.Path;
}
- return false;
}
}
}
\ No newline at end of file
diff --git a/Sources/Linaris/MainPage.xaml b/Sources/Linaris/MainPage.xaml
index 5881f1a..70b7a4c 100644
--- a/Sources/Linaris/MainPage.xaml
+++ b/Sources/Linaris/MainPage.xaml
@@ -39,7 +39,7 @@
-
+
diff --git a/Sources/Linaris/MainPage.xaml.cs b/Sources/Linaris/MainPage.xaml.cs
index 9ab2ab9..6f88154 100644
--- a/Sources/Linaris/MainPage.xaml.cs
+++ b/Sources/Linaris/MainPage.xaml.cs
@@ -31,5 +31,16 @@ public partial class MainPage : ContentPage
}
}
}
+
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ musicElement.Stop();
+ }
+ }
}
diff --git a/Sources/Linaris/PlaylistPage.xaml b/Sources/Linaris/PlaylistPage.xaml
index 65563b6..63c61fd 100644
--- a/Sources/Linaris/PlaylistPage.xaml
+++ b/Sources/Linaris/PlaylistPage.xaml
@@ -42,6 +42,6 @@
-
+
\ No newline at end of file
diff --git a/Sources/Linaris/PlaylistPage.xaml.cs b/Sources/Linaris/PlaylistPage.xaml.cs
index 6859e57..26fc7cc 100644
--- a/Sources/Linaris/PlaylistPage.xaml.cs
+++ b/Sources/Linaris/PlaylistPage.xaml.cs
@@ -1,13 +1,17 @@
+using CommunityToolkit.Maui.Views;
using Model;
+using Model.Stub;
namespace Linaris;
public partial class PlaylistPage : ContentPage
{
+ private readonly Manager Manager = (Application.Current as App).Manager;
+
public PlaylistPage()
{
InitializeComponent();
- BindingContext = (Application.Current as App).Manager.CurrentPlaylist;
+ BindingContext = Manager.CurrentPlaylist;
}
private async void EditPlaylist(object sender, EventArgs e)
@@ -21,7 +25,7 @@ public partial class PlaylistPage : ContentPage
{
if (menuItem.BindingContext is CustomTitle customTitle)
{
- (Application.Current as App).Manager.GetPlaylistByName((Application.Current as App).Manager.CurrentPlaylist.Name).RemoveTitle(customTitle);
+ Manager.GetPlaylistByName(Manager.CurrentPlaylist.Name).RemoveTitle(customTitle);
}
}
}
@@ -33,20 +37,47 @@ public partial class PlaylistPage : ContentPage
{
if (button.BindingContext is Playlist playlist)
{
- (Application.Current as App).Manager.CurrentPlaying = playlist.Titles.FirstOrDefault();
- if ((Application.Current as App).Manager.CurrentPlaying == null) return;
+ Manager.CurrentPlaylist = playlist;
+ Manager.NextTitle();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ if (Manager.CurrentPlaying == null) return;
+ musicElement.Source = Manager.CurrentPlaying.Path;
+ }
}
}
}
private void RdmPlay(object sender, EventArgs e)
- {
- /*if (sender is Button button)
- {
- if (button.BindingContext is Playlist playlist)
- {
- (Application.Current as App).Manager.CurrentPlaying = playlist.GetCurrentTitle();
+ {
+ if (sender is Button button)
+ {
+ if (button.BindingContext is Playlist playlist)
+ {
+ Manager.CurrentPlaylist = playlist;
+ Manager.Shuffle();
+ Manager.NextTitle();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ if (Manager.CurrentPlaying == null) return;
+ musicElement.Source = Manager.CurrentPlaying.Path;
+ }
}
- }*/
+ }
+ }
+
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ musicElement.Stop();
+ }
}
}
\ No newline at end of file
diff --git a/Sources/Linaris/PlaylistsPage.xaml b/Sources/Linaris/PlaylistsPage.xaml
index d393c5c..e0b2c77 100644
--- a/Sources/Linaris/PlaylistsPage.xaml
+++ b/Sources/Linaris/PlaylistsPage.xaml
@@ -46,7 +46,7 @@
-
+
diff --git a/Sources/Linaris/PlaylistsPage.xaml.cs b/Sources/Linaris/PlaylistsPage.xaml.cs
index 00a74eb..8fb4e68 100644
--- a/Sources/Linaris/PlaylistsPage.xaml.cs
+++ b/Sources/Linaris/PlaylistsPage.xaml.cs
@@ -1,3 +1,4 @@
+using CommunityToolkit.Maui.Views;
using Model;
using System.Collections.ObjectModel;
@@ -112,4 +113,15 @@ public partial class PlaylistsPage : ContentPage
}
await Navigation.PushAsync(new PlaylistPage());
}
+
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+ ContentView footer = this.FindByName("Footer");
+ var musicElement = footer?.FindByName("music");
+ if (musicElement != null)
+ {
+ musicElement.Stop();
+ }
+ }
}
\ No newline at end of file
diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs
index b79b133..32606a2 100644
--- a/Sources/Model/Manager.cs
+++ b/Sources/Model/Manager.cs
@@ -4,8 +4,13 @@ using System.Runtime.CompilerServices;
namespace Model.Stub;
-public class Manager
-{
+public class Manager : INotifyPropertyChanged
+{
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
+ => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+
public readonly static int MAX_NAME_LENGTH = 75;
public readonly static int MAX_DESCRIPTION_LENGTH = 500;
@@ -72,13 +77,11 @@ public class Manager
public Album CurrentAlbum
{
- get
- {
- return currentAlbum;
- }
+ get => currentAlbum;
set
{
currentAlbum = value;
+ OnPropertyChanged();
}
}
@@ -90,6 +93,7 @@ public class Manager
set
{
currentPlaylist = value;
+ OnPropertyChanged();
}
}
@@ -101,6 +105,7 @@ public class Manager
set
{
currentInfoTitle = value;
+ OnPropertyChanged();
}
}
@@ -112,6 +117,7 @@ public class Manager
set
{
currentPlaying = value;
+ OnPropertyChanged();
}
}
@@ -127,10 +133,40 @@ public class Manager
currentAlbum = albums.First();
currentPlaylist = playlists.FirstOrDefault();
- currentInfoTitle = infoTitles.FirstOrDefault();
+ currentInfoTitle = null;
currentPlaying = null;
}
+ public void NextTitle()
+ {
+ if (currentPlaylist == null) return;
+ currentPlaying = currentPlaylist.NextTitle();
+ }
+
+ public void PreviousTitle()
+ {
+ if (CurrentPlaying == null) return;
+ currentPlaying = currentPlaylist.PreviousTitle();
+ }
+
+ public CustomTitle CurrentTitle()
+ {
+ if (CurrentPlaylist == null) return null;
+ return currentPlaylist.GetCurrentTitle();
+ }
+
+ public void Loop()
+ {
+ if (CurrentPlaylist == null) return;
+ currentPlaylist.LoopTitle = !currentPlaylist.LoopTitle;
+ }
+
+ public void Shuffle()
+ {
+ if (CurrentPlaylist == null) return;
+ currentPlaylist.Shuffle = !currentPlaylist.Shuffle;
+ }
+
public void AddAlbum(Album album)
{
if (GetAlbumByName(album.Name) != null) return;
diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs
index fa64f77..5458b70 100644
--- a/Sources/Model/Playlist.cs
+++ b/Sources/Model/Playlist.cs
@@ -92,19 +92,17 @@ public class Playlist : INotifyPropertyChanged
{
index = value;
}
- else if(Loop)
+ else
{
index = 0;
}
}
}
- private int index = 0;
+ private int index = -1;
public bool Shuffle { get; set; } = false;
- public bool Loop { get; set; } = false;
-
public bool LoopTitle { get; set; } = false;
private readonly List played = new List();
@@ -139,10 +137,7 @@ public class Playlist : INotifyPropertyChanged
ImageURL = imageURL;
}
- public Playlist()
- {
-
- }
+ public Playlist() { }
public void AddTitle(CustomTitle morceau)
{
@@ -154,30 +149,33 @@ public class Playlist : INotifyPropertyChanged
titles.Remove(morceau);
}
- public void NextTitle()
+ public CustomTitle NextTitle()
{
+ if (titles.Count < 1) return null;
if (LoopTitle)
{
- return;
+ return GetCurrentTitle();
}
if (!Shuffle)
{
Index++;
played.Add(Index);
+ return GetCurrentTitle();
}
else
{
Index = RandomGenerator(titles.Count);
played.Add(Index);
+ return GetCurrentTitle();
}
}
- public void PreviousTitle()
+ public CustomTitle PreviousTitle()
{
if (LoopTitle)
{
- return;
+ return GetCurrentTitle();
}
if(!Shuffle)
@@ -186,21 +184,28 @@ public class Playlist : INotifyPropertyChanged
{
Index--;
played.RemoveAt(played.Count - 1);
+ return GetCurrentTitle();
+ }
+ else
+ {
+ return GetCurrentTitle();
}
}
else
{
if (!played.Any())
{
- return;
+ return GetCurrentTitle();
}
Index = played[played.Count - 1];
played.RemoveAt(played.Count - 1);
+ return GetCurrentTitle();
}
}
public CustomTitle GetCurrentTitle()
{
+ if (Index < 0) Index = 0;
if (Index < titles.Count)
{
return titles[Index];
@@ -235,8 +240,8 @@ public class Playlist : INotifyPropertyChanged
RandomNumberGenerator rng = RandomNumberGenerator.Create();
byte[] randomBytes = new byte[4];
rng.GetBytes(randomBytes);
- int randomNumber = BitConverter.ToInt32(randomBytes, 0);
- return randomNumber % n + 1;
+ uint randomNumber = BitConverter.ToUInt32(randomBytes, 0);
+ return (int)(randomNumber % n) + 1;
}
public bool HasCustomTitle(CustomTitle customTitle)