Footer get and set data between different pages + fix local files scrollview bug
continuous-integration/drone/push Build is passing Details

pull/37/head
Corentin LEMAIRE 2 years ago
parent 2a8bfe79b3
commit 1200aa95b3

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
using Model;
@ -33,9 +34,16 @@ public partial class AlbumPage : ContentPage
}
}
protected override void OnAppearing()
{
base.OnAppearing();
GetFooterData();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
SetFooterData();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
@ -43,4 +51,50 @@ public partial class AlbumPage : ContentPage
musicElement.Stop();
}
}
private void GetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
Footer.CurrentPlaying = FooterPage.CurrentPlaying;
Footer.PlayImage = FooterPage.PlayImage;
Footer.LoopImage = FooterPage.LoopImage;
Footer.ShuffleImage = FooterPage.ShuffleImage;
Footer.Volume = FooterPage.Volume;
Footer.Position = FooterPage.Position;
Footer.Duration = FooterPage.Duration;
Footer.SliderPosition = FooterPage.SliderPosition;
// Place l'index de lecture de la musique à la position du slider
var musicElement = Footer?.FindByName<MediaElement>("music");
musicElement.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(100), () =>
{
musicElement.SeekTo((Application.Current as App).MusicPosition);
return false;
});
if ((Application.Current as App).MediaState == MediaElementState.Playing)
{
musicElement.Play();
}
else
{
musicElement.Pause();
}
}
public void SetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
FooterPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying;
FooterPage.PlayImage = Footer.PlayImage;
FooterPage.LoopImage = Footer.LoopImage;
FooterPage.ShuffleImage = Footer.ShuffleImage;
FooterPage.Volume = Footer.Volume;
FooterPage.Position = Footer.Position;
FooterPage.Duration = Footer.Duration;
FooterPage.SliderPosition = Footer.SliderPosition;
var musicElement = Footer?.FindByName<MediaElement>("music");
(Application.Current as App).MusicPosition = musicElement.Position;
(Application.Current as App).MediaState = musicElement.CurrentState;
}
}

@ -1,15 +1,60 @@
using Model.Serialization;
using CommunityToolkit.Maui.Core.Primitives;
using Model.Serialization;
using Model.Stub;
namespace Linaris;
public partial class App : Application
{
public Manager Manager = new(new LinqXmlSerialization(FileSystem.Current.AppDataDirectory));
private Manager manager = new(new LinqXmlSerialization(FileSystem.Current.AppDataDirectory));
public Manager Manager
{
get => manager;
set
{
manager = value;
}
}
private FooterPage footerPage;
public FooterPage FooterPage
{
get => footerPage;
set
{
footerPage = value;
}
}
private TimeSpan musicPosition = TimeSpan.FromSeconds(0);
public TimeSpan MusicPosition
{
get => musicPosition;
set
{
musicPosition = value;
}
}
private MediaElementState mediaState = MediaElementState.Paused;
public MediaElementState MediaState
{
get => mediaState;
set
{
mediaState = value;
}
}
public App()
{
InitializeComponent();
footerPage = new FooterPage();
MainPage = new AppShell();
}

@ -6,12 +6,12 @@
xmlns:model="clr-namespace:Model;assembly=Model"
x:Class="Linaris.FooterPage">
<Grid Grid.ColumnSpan="2" Grid.Row="1" BackgroundColor="Gray">
<Grid Grid.ColumnSpan="2" Grid.Row="1" BackgroundColor="Gray" BindingContext="{Binding CurrentPlaying}">
<toolkit:MediaElement IsVisible="False" x:Name="music" Source="{Binding CurrentPlaying.Path}" BackgroundColor="Transparent" ShouldShowPlaybackControls="True" ShouldAutoPlay="True" Grid.Column="0" ShouldKeepScreenOn="false" MediaEnded="OnCompleted"/>
<toolkit:MediaElement IsVisible="False" x:Name="music" Source="{Binding Path}" BackgroundColor="Transparent" ShouldShowPlaybackControls="False" ShouldAutoPlay="True" Grid.Column="0" ShouldKeepScreenOn="false" MediaEnded="OnCompleted"/>
<Grid ColumnDefinitions="*,3*,*" RowDefinitions="8*,3*">
<Label Style="{StaticResource FooterTitleTrigger}" Text="{Binding CurrentPlaying.Name}" TextColor="PeachPuff" x:Name="Title" HorizontalOptions="Center" VerticalOptions="Center" LineBreakMode="TailTruncation" Grid.Row="0"/>
<Label Style="{StaticResource FooterTitleTrigger}" Text="{Binding Name}" TextColor="PeachPuff" x:Name="Title" HorizontalOptions="Center" VerticalOptions="Center" LineBreakMode="TailTruncation" Grid.Row="0"/>
<Grid ColumnDefinitions="*,3*,*" Grid.ColumnSpan="3" RowDefinitions="8*,3*" Grid.RowSpan="2">
<HorizontalStackLayout Grid.Row="0" Grid.Column="1" HorizontalOptions="Center">

@ -3,11 +3,14 @@ using Model;
using Model.Stub;
using System.ComponentModel;
using System.Configuration;
using System.Runtime.CompilerServices;
namespace Linaris;
public partial class FooterPage : ContentView, INotifyPropertyChanged
{
public new event PropertyChangedEventHandler PropertyChanged;
private CustomTitle currentPlaying;
public CustomTitle CurrentPlaying
@ -16,7 +19,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
currentPlaying = value;
OnPropertyChanged(nameof(CurrentPlaying));
OnPropertyChanged();
}
}
@ -28,7 +31,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
playImage = value;
OnPropertyChanged(nameof(PlayImage));
OnPropertyChanged();
}
}
@ -40,7 +43,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
loopImage = value;
OnPropertyChanged(nameof(LoopImage));
OnPropertyChanged();
}
}
@ -52,7 +55,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
shuffleImage = value;
OnPropertyChanged(nameof(ShuffleImage));
OnPropertyChanged();
}
}
@ -64,7 +67,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
volume = value;
OnPropertyChanged(nameof(Volume));
OnPropertyChanged();
}
}
@ -76,7 +79,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
position = value;
OnPropertyChanged(nameof(Position));
OnPropertyChanged();
}
}
@ -88,7 +91,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
duration = value;
OnPropertyChanged(nameof(Duration));
OnPropertyChanged();
}
}
@ -100,7 +103,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
set
{
sliderPosition = value;
OnPropertyChanged(nameof(SliderPosition));
OnPropertyChanged();
}
}
@ -114,6 +117,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
public FooterPage()
{
InitializeComponent();
music.StateChanged += Music_StateChanged;
TimeSlider.ValueChanged += TimeSlider_ValueChanged;
VolumeSlider.ValueChanged += VolumeSlider_ValueChanged;
@ -126,6 +130,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
{
SliderPosition = music.Position.TotalSeconds / music.Duration.TotalSeconds;
Position = music.Position.ToString(@"hh\:mm\:ss");
Duration = music.Duration.ToString(@"hh\:mm\:ss");
}
private void VolumeSlider_ValueChanged(object sender, ValueChangedEventArgs e)
@ -155,7 +160,6 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
else
{
PlayImage = "pause.png";
Duration = music.Duration.ToString(@"hh\:mm\:ss");
}
}
@ -163,10 +167,11 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
{
if (Manager.CurrentPlaylist == null || Manager.CurrentPlaying == null) return;
Manager.PreviousTitle();
CurrentPlaying = Manager.CurrentPlaying;
Dispatcher.DispatchAsync(() =>
{
string encodedFilePath = Manager.CurrentPlaying.Path.Replace(" ", "\\ ");
music.Source = encodedFilePath;
music.Source = Manager.CurrentPlaying.Path;
music.SeekTo(TimeSpan.FromSeconds(0));
Duration = music.Duration.ToString(@"hh\:mm\:ss");
});
}
@ -175,10 +180,11 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
{
if (Manager.CurrentPlaylist == null || Manager.CurrentPlaying == null) return;
Manager.NextTitle();
CurrentPlaying = Manager.CurrentPlaying;
Dispatcher.DispatchAsync(() =>
{
string encodedFilePath = Manager.CurrentPlaying.Path.Replace(" ", "\\ ");
music.Source = encodedFilePath;
music.Source = Manager.CurrentPlaying.Path;
music.SeekTo(TimeSpan.FromSeconds(0));
Duration = music.Duration.ToString(@"hh\:mm\:ss");
});
}
@ -209,14 +215,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
public void OnCompleted(object sender, EventArgs e)
{
if (Manager.CurrentPlaying == null) return;
Manager.NextTitle();
Dispatcher.DispatchAsync(() =>
{
string encodedFilePath = Manager.CurrentPlaying.Path.Replace(" ", "\\ ");
music.Source = encodedFilePath;
Duration = music.Duration.ToString(@"hh\:mm\:ss");
});
NextButton_Clicked(sender, e);
}
public void PlayButton_Clicked(object sender, EventArgs e)
@ -230,4 +229,7 @@ public partial class FooterPage : ContentView, INotifyPropertyChanged
music.Pause();
}
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
using Model;
@ -27,9 +28,16 @@ public partial class InfoTitlePage : ContentPage
BindingContext = this;
}
protected override void OnAppearing()
{
base.OnAppearing();
GetFooterData();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
SetFooterData();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
@ -37,4 +45,50 @@ public partial class InfoTitlePage : ContentPage
musicElement.Stop();
}
}
private void GetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
Footer.CurrentPlaying = FooterPage.CurrentPlaying;
Footer.PlayImage = FooterPage.PlayImage;
Footer.LoopImage = FooterPage.LoopImage;
Footer.ShuffleImage = FooterPage.ShuffleImage;
Footer.Volume = FooterPage.Volume;
Footer.Position = FooterPage.Position;
Footer.Duration = FooterPage.Duration;
Footer.SliderPosition = FooterPage.SliderPosition;
// Place l'index de lecture de la musique à la position du slider
var musicElement = Footer?.FindByName<MediaElement>("music");
musicElement.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(300), () =>
{
musicElement.SeekTo((Application.Current as App).MusicPosition);
return false;
});
if ((Application.Current as App).MediaState == MediaElementState.Playing)
{
musicElement.Play();
}
else
{
musicElement.Pause();
}
}
public void SetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
FooterPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying;
FooterPage.PlayImage = Footer.PlayImage;
FooterPage.LoopImage = Footer.LoopImage;
FooterPage.ShuffleImage = Footer.ShuffleImage;
FooterPage.Volume = Footer.Volume;
FooterPage.Position = Footer.Position;
FooterPage.Duration = Footer.Duration;
FooterPage.SliderPosition = Footer.SliderPosition;
var musicElement = Footer?.FindByName<MediaElement>("music");
(Application.Current as App).MusicPosition = musicElement.Position;
(Application.Current as App).MediaState = musicElement.CurrentState;
}
}

@ -11,50 +11,21 @@ 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)
{
StopMusic();
await Navigation.PushAsync(new PlaylistsPage());
}
private async void Go_Back(object sender, EventArgs e)
{
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<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("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;
}
}

@ -55,7 +55,6 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="NAudio" Version="2.1.0" />
<PackageReference Include="Plugin.Maui.Audio" Version="1.0.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
</ItemGroup>
<ItemGroup>

@ -14,7 +14,7 @@
<Grid Style="{StaticResource GridFlyoutTrigger}" RowDefinitions="*,100">
<local:Layout Grid.Column="0"/>
<ScrollView Grid.Column="1" Grid.Row="0" BackgroundColor="#404040">
<ScrollView Grid.Column="1" Grid.Row="0" BackgroundColor="#404040" x:Name="MainScrollView">
<VerticalStackLayout>
<local:SearchBarView/>

@ -1,7 +1,12 @@
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Platform;
using Model;
using Model.Stub;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
namespace Linaris;
@ -87,11 +92,15 @@ public partial class LocalFilesPage : ContentPage
return;
}
if (sender is Button button)
foreach (var result in results)
{
foreach (var result in results)
string path = Path.Combine(FileSystem.Current.AppDataDirectory, "customs");
if (!Path.Exists(path)) Directory.CreateDirectory(path);
string fullPath = Path.Combine(path, result.FileName);
if (!File.Exists(fullPath))
{
CustomTitle custom = new (result.FileName, "none.png", "", result.FullPath);
File.Copy(result.FullPath, fullPath);
CustomTitle custom = new(result.FileName, "none.png", "", fullPath);
if (!IsCustomTitleInCollection(custom))
{
AddCustomTitle(custom);
@ -149,6 +158,7 @@ public partial class LocalFilesPage : ContentPage
{
(Application.Current as App).Manager.RemoveCustomTitle(titleToRemove);
customTitles.Remove(titleToRemove);
File.Delete(titleToRemove.Path);
}
}
}
@ -156,22 +166,20 @@ public partial class LocalFilesPage : ContentPage
// Show methods
void ShowSubMenu(object sender, EventArgs e)
async void ShowSubMenu(object sender, EventArgs e)
{
if (sender is Image image)
if (sender is Image image && 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);
}
await MainScrollView.ScrollToAsync(image, ScrollToPosition.Center, true);
}
}
@ -254,9 +262,16 @@ public partial class LocalFilesPage : ContentPage
return false;
}
protected override void OnAppearing()
{
base.OnAppearing();
GetFooterData();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
SetFooterData();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
@ -265,6 +280,52 @@ public partial class LocalFilesPage : ContentPage
}
}
private void GetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
Footer.CurrentPlaying = FooterPage.CurrentPlaying;
Footer.PlayImage = FooterPage.PlayImage;
Footer.LoopImage = FooterPage.LoopImage;
Footer.ShuffleImage = FooterPage.ShuffleImage;
Footer.Volume = FooterPage.Volume;
Footer.Position = FooterPage.Position;
Footer.Duration = FooterPage.Duration;
Footer.SliderPosition = FooterPage.SliderPosition;
// Place l'index de lecture de la musique à la position du slider
var musicElement = Footer?.FindByName<MediaElement>("music");
musicElement.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(1000), () =>
{
musicElement.SeekTo((Application.Current as App).MusicPosition);
if ((Application.Current as App).MediaState == MediaElementState.Playing)
{
musicElement.Play();
}
else
{
musicElement.Pause();
}
return false;
});
}
public void SetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
FooterPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying;
FooterPage.PlayImage = Footer.PlayImage;
FooterPage.LoopImage = Footer.LoopImage;
FooterPage.ShuffleImage = Footer.ShuffleImage;
FooterPage.Volume = Footer.Volume;
FooterPage.Position = Footer.Position;
FooterPage.Duration = Footer.Duration;
FooterPage.SliderPosition = Footer.SliderPosition;
var musicElement = Footer?.FindByName<MediaElement>("music");
(Application.Current as App).MusicPosition = musicElement.Position;
(Application.Current as App).MediaState = musicElement.CurrentState;
}
// Others
@ -278,11 +339,15 @@ public partial class LocalFilesPage : ContentPage
if (musicElement != null)
{
musicElement.Source = customTitle.Path;
musicElement.SeekTo(TimeSpan.FromSeconds(0));
musicElement.Play();
}
if (footer is FooterPage footerPage)
{
footerPage.CurrentPlaying = customTitle;
}
(Application.Current as App).Manager.CurrentPlaylist = null;
(Application.Current as App).Manager.CurrentPlaying = customTitle;
}
}
}

@ -1,4 +1,5 @@
using CommunityToolkit.Maui.Views;
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
using Model;
using System.Collections.ObjectModel;
@ -20,7 +21,7 @@ public partial class MainPage : ContentPage
BindingContext = this;
}
async void GoToAlbum(object sender, EventArgs e)
async void GoToAlbum(object sender, EventArgs e)
{
if (sender is Image image)
{
@ -32,9 +33,16 @@ public partial class MainPage : ContentPage
}
}
protected override void OnAppearing()
{
base.OnAppearing();
GetFooterData();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
SetFooterData();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
@ -42,5 +50,51 @@ public partial class MainPage : ContentPage
musicElement.Stop();
}
}
private void GetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
Footer.CurrentPlaying = FooterPage.CurrentPlaying;
Footer.PlayImage = FooterPage.PlayImage;
Footer.LoopImage = FooterPage.LoopImage;
Footer.ShuffleImage = FooterPage.ShuffleImage;
Footer.Volume = FooterPage.Volume;
Footer.Position = FooterPage.Position;
Footer.Duration = FooterPage.Duration;
Footer.SliderPosition = FooterPage.SliderPosition;
// Place l'index de lecture de la musique à la position du slider
var musicElement = Footer?.FindByName<MediaElement>("music");
musicElement.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(100), () =>
{
musicElement.SeekTo((Application.Current as App).MusicPosition);
return false;
});
if ((Application.Current as App).MediaState == MediaElementState.Playing)
{
musicElement.Play();
}
else
{
musicElement.Pause();
}
}
public void SetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
FooterPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying;
FooterPage.PlayImage = Footer.PlayImage;
FooterPage.LoopImage = Footer.LoopImage;
FooterPage.ShuffleImage = Footer.ShuffleImage;
FooterPage.Volume = Footer.Volume;
FooterPage.Position = Footer.Position;
FooterPage.Duration = Footer.Duration;
FooterPage.SliderPosition = Footer.SliderPosition;
var musicElement = Footer?.FindByName<MediaElement>("music");
(Application.Current as App).MusicPosition = musicElement.Position;
(Application.Current as App).MediaState = musicElement.CurrentState;
}
}

@ -3,6 +3,11 @@
<application android:allowBackup="false" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:usesCleartextTraffic="false"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" android:minSdkVersion="32"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" android:minSdkVersion="32"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" android:minSdkVersion="32"/>
</manifest>

@ -36,7 +36,7 @@
<MenuItem Text="Supprimer" Clicked="RemoveCustomTitle"/>
</ViewCell.ContextActions>
<Frame Style="{StaticResource Song}" Padding="0">
<Label Text="{Binding Name}" FontSize="20" TextColor="white" HorizontalTextAlignment="Center" VerticalOptions="Center"/>
<Label Text="{Binding Name}" FontSize="20" TextColor="white" HorizontalTextAlignment="Center" VerticalOptions="Center" LineBreakMode="TailTruncation"/>
</Frame>
</ViewCell>
</DataTemplate>

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
using Model;
using Model.Stub;
@ -44,8 +45,9 @@ public partial class PlaylistPage : ContentPage
if (musicElement != null)
{
if (Manager.CurrentPlaying == null) return;
string encodedFilePath = Manager.CurrentPlaying.Path.Replace(" ", "\\ ");
musicElement.Source = encodedFilePath;
musicElement.Source = Manager.CurrentPlaying.Path;
musicElement.SeekTo(TimeSpan.FromSeconds(0));
musicElement.Play();
}
if (footer is FooterPage footerPage)
{
@ -70,18 +72,28 @@ public partial class PlaylistPage : ContentPage
{
if (Manager.CurrentPlaying == null) return;
musicElement.Source = Manager.CurrentPlaying.Path;
musicElement.SeekTo(TimeSpan.FromSeconds(0));
musicElement.Play();
if (footer is FooterPage footerPage)
{
footerPage.ShuffleImage = "rdm2.png";
footerPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying;
}
}
}
}
}
protected override void OnAppearing()
{
base.OnAppearing();
GetFooterData();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
SetFooterData();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
@ -89,4 +101,50 @@ public partial class PlaylistPage : ContentPage
musicElement.Stop();
}
}
private void GetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
Footer.CurrentPlaying = FooterPage.CurrentPlaying;
Footer.PlayImage = FooterPage.PlayImage;
Footer.LoopImage = FooterPage.LoopImage;
Footer.ShuffleImage = FooterPage.ShuffleImage;
Footer.Volume = FooterPage.Volume;
Footer.Position = FooterPage.Position;
Footer.Duration = FooterPage.Duration;
Footer.SliderPosition = FooterPage.SliderPosition;
// Place l'index de lecture de la musique à la position du slider
var musicElement = Footer?.FindByName<MediaElement>("music");
musicElement.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(100), () =>
{
musicElement.SeekTo((Application.Current as App).MusicPosition);
return false;
});
if ((Application.Current as App).MediaState == MediaElementState.Playing)
{
musicElement.Play();
}
else
{
musicElement.Pause();
}
}
public void SetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
FooterPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying;
FooterPage.PlayImage = Footer.PlayImage;
FooterPage.LoopImage = Footer.LoopImage;
FooterPage.ShuffleImage = Footer.ShuffleImage;
FooterPage.Volume = Footer.Volume;
FooterPage.Position = Footer.Position;
FooterPage.Duration = Footer.Duration;
FooterPage.SliderPosition = Footer.SliderPosition;
var musicElement = Footer?.FindByName<MediaElement>("music");
(Application.Current as App).MusicPosition = musicElement.Position;
(Application.Current as App).MediaState = musicElement.CurrentState;
}
}

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
using Model;
using System.Collections.ObjectModel;
@ -114,9 +115,16 @@ public partial class PlaylistsPage : ContentPage
await Navigation.PushAsync(new PlaylistPage());
}
protected override void OnAppearing()
{
base.OnAppearing();
GetFooterData();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
SetFooterData();
ContentView footer = this.FindByName<ContentView>("Footer");
var musicElement = footer?.FindByName<MediaElement>("music");
if (musicElement != null)
@ -124,4 +132,50 @@ public partial class PlaylistsPage : ContentPage
musicElement.Stop();
}
}
private void GetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
Footer.CurrentPlaying = FooterPage.CurrentPlaying;
Footer.PlayImage = FooterPage.PlayImage;
Footer.LoopImage = FooterPage.LoopImage;
Footer.ShuffleImage = FooterPage.ShuffleImage;
Footer.Volume = FooterPage.Volume;
Footer.Position = FooterPage.Position;
Footer.Duration = FooterPage.Duration;
Footer.SliderPosition = FooterPage.SliderPosition;
// Place l'index de lecture de la musique à la position du slider
var musicElement = Footer?.FindByName<MediaElement>("music");
musicElement.Dispatcher.StartTimer(TimeSpan.FromMilliseconds(100), () =>
{
musicElement.SeekTo((Application.Current as App).MusicPosition);
return false;
});
if ((Application.Current as App).MediaState == MediaElementState.Playing)
{
musicElement.Play();
}
else
{
musicElement.Pause();
}
}
public void SetFooterData()
{
FooterPage FooterPage = (Application.Current as App).FooterPage;
FooterPage.CurrentPlaying = (Application.Current as App).Manager.CurrentPlaying;
FooterPage.PlayImage = Footer.PlayImage;
FooterPage.LoopImage = Footer.LoopImage;
FooterPage.ShuffleImage = Footer.ShuffleImage;
FooterPage.Volume = Footer.Volume;
FooterPage.Position = Footer.Position;
FooterPage.Duration = Footer.Duration;
FooterPage.SliderPosition = Footer.SliderPosition;
var musicElement = Footer?.FindByName<MediaElement>("music");
(Application.Current as App).MusicPosition = musicElement.Position;
(Application.Current as App).MediaState = musicElement.CurrentState;
}
}

@ -232,7 +232,7 @@ public class LinqXmlSerialization : IDataManager
string[] customArray = allCustoms.Split(separator, StringSplitOptions.RemoveEmptyEntries);
List<string> customsList = customArray.ToList();
foreach(var custom in customsList)
foreach (var custom in customsList)
{
CustomTitle customTitle = GetCustomTitleByPath(custom);
@ -261,15 +261,15 @@ public class LinqXmlSerialization : IDataManager
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using(TextWriter tw = File.CreateText(XMLFILEPLAYLISTS))
using (TextWriter tw = File.CreateText(XMLFILEPLAYLISTS))
{
using(XmlWriter writer = XmlWriter.Create(tw, settings))
using (XmlWriter writer = XmlWriter.Create(tw, settings))
{
PlaylistsFichier.Save(writer);
}
}
}
public void LoadArtists()
{
artists = StubInfoTitle.StubAlbum.StubArtist.GetArtists();
@ -291,7 +291,7 @@ public class LinqXmlSerialization : IDataManager
new XAttribute("Name", c.Name),
new XElement("ImageURL", c.ImageURL),
new XElement("Information", c.Information),
new XElement("Path",c.Path)
new XElement("Path", c.Path)
));
CustomsFile2.Add(new XElement("Customs", custom));
@ -301,7 +301,7 @@ public class LinqXmlSerialization : IDataManager
using (TextWriter tw = File.CreateText(XMLFILECUSTOMS))
{
using (XmlWriter writer = XmlWriter.Create(tw, settings))
CustomsFile2.Save(writer);
}
}

@ -5,9 +5,8 @@ using System.Xml.Serialization;
namespace Model;
public class Title
public class Title : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public string Name

Loading…
Cancel
Save