beginnings of fullscreen

This commit is contained in:
Royce551 2021-09-11 23:28:05 -05:00
parent 10763eb11a
commit f5d193d961
5 changed files with 256 additions and 35 deletions

View file

@ -130,6 +130,9 @@
<Compile Include="Handlers\Notifications\Notification.cs" />
<Compile Include="Handlers\PlaytimeTrackingHandler.cs" />
<Compile Include="Handlers\UpdateHandler.cs" />
<Compile Include="Pages\FullscreenPage.xaml.cs">
<DependentUpon>FullscreenPage.xaml</DependentUpon>
</Compile>
<Compile Include="Pages\ImportPage.xaml.cs">
<DependentUpon>ImportPage.xaml</DependentUpon>
</Compile>
@ -213,6 +216,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Pages\FullscreenPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Pages\ImportPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View file

@ -34,6 +34,7 @@ namespace FRESHMusicPlayer
Albums,
Playlists,
Import,
Fullscreen,
Other
}
public enum AuxiliaryPane
@ -64,7 +65,7 @@ namespace FRESHMusicPlayer
public bool PauseAfterCurrentTrack = false;
private FileSystemWatcher watcher = new FileSystemWatcher(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer"));
private WinForms.Timer progressTimer;
public WinForms.Timer ProgressTimer;
private IPlaybackIntegration smtcIntegration; // might be worth making some kind of manager for these, but i'm lazy so -\_(:/)_/-
private IPlaybackIntegration discordIntegration;
public MainWindow(Player player, string[] initialFile = null)
@ -76,11 +77,11 @@ namespace FRESHMusicPlayer
Player.SongStopped += Player_SongStopped;
Player.SongException += Player_SongException;
NotificationHandler.NotificationInvalidate += NotificationHandler_NotificationInvalidate;
progressTimer = new WinForms.Timer
ProgressTimer = new WinForms.Timer
{
Interval = 100
};
progressTimer.Tick += ProgressTimer_Tick;
ProgressTimer.Tick += ProgressTimer_Tick;
Initialize(initialFile);
}
@ -146,13 +147,13 @@ namespace FRESHMusicPlayer
{
Player.Resume();
SetIntegrations(PlaybackStatus.Playing);
progressTimer.Start();
ProgressTimer.Start();
}
else
{
Player.Pause();
SetIntegrations(PlaybackStatus.Paused);
progressTimer.Stop();
ProgressTimer.Stop();
}
UpdatePlayButtonState();
}
@ -169,7 +170,7 @@ namespace FRESHMusicPlayer
else
{
Player.CurrentTime = TimeSpan.FromSeconds(0);
progressTimer.Start(); // to resync the progress timer
ProgressTimer.Start(); // to resync the progress timer
}
}
public void ShuffleMethod()
@ -258,16 +259,13 @@ namespace FRESHMusicPlayer
RightFrame.Visibility = Visibility.Visible;
RightFrame.Width = width;
var sb = new Storyboard();
var ta = new ThicknessAnimation();
ta.SetValue(Storyboard.TargetNameProperty, "RightFrame");
Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
var sb = InterfaceUtils.GetThicknessAnimation(
openleft ? new Thickness(width * -1 /*negate*/, 0, 0, 0) : new Thickness(0, 0, width * -1 /*negate*/, 0),
new Thickness(0),
TimeSpan.FromMilliseconds(120),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseOut, Exponent = 3 });
ta.To = new Thickness(0);
ta.From = openleft ? new Thickness(width * -1 /*negate*/, 0, 0, 0) : new Thickness(0, 0, width * -1 /*negate*/, 0);
ta.EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut, Exponent = 3 };
ta.Duration = new Duration(TimeSpan.FromMilliseconds(120));
sb.Children.Add(ta);
sb.Begin(RightFrame);
SelectedAuxiliaryPane = pane;
@ -275,17 +273,12 @@ namespace FRESHMusicPlayer
}
public async Task HideAuxilliaryPane(bool animate = true)
{
var sb = new Storyboard();
var ta = new ThicknessAnimation();
ta.SetValue(Storyboard.TargetNameProperty, "RightFrame");
Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty));
ta.From = new Thickness(0);
ta.To = DockPanel.GetDock(RightFrame) == Dock.Left ? new Thickness(RightFrame.Width * -1, 0, 0, 0) : new Thickness(0, 0, RightFrame.Width * -1, 0);
ta.EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 };
ta.Duration = new Duration(TimeSpan.FromMilliseconds(120));
sb.Children.Add(ta);
sb.Begin(RightFrame);
var sb = InterfaceUtils.GetThicknessAnimation(
new Thickness(0),
DockPanel.GetDock(RightFrame) == Dock.Left ? new Thickness(RightFrame.Width * -1, 0, 0, 0) : new Thickness(0, 0, RightFrame.Width * -1, 0),
TimeSpan.FromMilliseconds(120),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
if (animate) await sb.BeginStoryboardAsync(RightFrame);
RightFrame.Visibility = Visibility.Collapsed;
@ -293,6 +286,46 @@ namespace FRESHMusicPlayer
RightFrame.Navigate(new object());
SelectedAuxiliaryPane = AuxiliaryPane.None;
}
public bool IsControlsBoxVisible { get; private set; } = false;
public void ShowControlsBox()
{
IsControlsBoxVisible = true;
var navBarStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0, -25, 0, 0),
new Thickness(0),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
var controlsBoxStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0, 0, 0, -84),
new Thickness(0),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
navBarStoryboard.Begin(MainBar);
controlsBoxStoryboard.Begin(ControlsBoxBorder);
}
public void HideControlsBox()
{
IsControlsBoxVisible = false;
var navBarStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0),
new Thickness(0, -25, 0, 0),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
var controlsBoxStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0),
new Thickness(0, 0, 0, -84),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
navBarStoryboard.Begin(MainBar);
controlsBoxStoryboard.Begin(ControlsBoxBorder);
}
public void ProcessSettings(bool initialize = false)
{
if (initialize)
@ -423,6 +456,10 @@ namespace FRESHMusicPlayer
ContentFrame.Navigate(new ImportPage(this));
tabLabel = ImportTab;
break;
case Menu.Fullscreen:
ContentFrame.Navigate(new FullscreenPage(this));
tabLabel = ImportTab;
break;
default:
tabLabel = null;
break;
@ -440,7 +477,7 @@ namespace FRESHMusicPlayer
{
Title = WindowName;
TitleLabel.Text = ArtistLabel.Text = Properties.Resources.MAINWINDOW_NOTHINGPLAYING;
progressTimer.Stop();
ProgressTimer.Stop();
CoverArtBox.Source = null;
SetIntegrations(PlaybackStatus.Stopped);
SetCoverArtVisibility(false);
@ -478,7 +515,7 @@ namespace FRESHMusicPlayer
CoverArtBox.Source = BitmapFrame.Create(new MemoryStream(CurrentTrack.CoverArt), BitmapCreateOptions.None, BitmapCacheOption.None);
SetCoverArtVisibility(true);
}
progressTimer.Start();
ProgressTimer.Start();
if (PauseAfterCurrentTrack && !Player.Paused)
{
PlayPauseMethod();
@ -509,13 +546,13 @@ namespace FRESHMusicPlayer
private void ProgressBar_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
{
isDragging = true;
progressTimer.Stop();
ProgressTimer.Stop();
}
private void ProgressBar_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
if (Player.FileLoaded)
{
progressTimer.Start();
ProgressTimer.Start();
}
isDragging = false;
}
@ -551,7 +588,7 @@ namespace FRESHMusicPlayer
if (!isDragging) ProgressBar.Value = time.TotalSeconds;
Player.AvoidNextQueue = false;
progressTimer.Start(); // resync the progress timer
ProgressTimer.Start(); // resync the progress timer
}
private void TrackTitle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => ShowAuxilliaryPane(AuxiliaryPane.TrackInfo, 235, true);
private void TrackTitle_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
@ -707,12 +744,16 @@ namespace FRESHMusicPlayer
{
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
ChangeTabs(Menu.Fullscreen);
TracksTab.Visibility = ArtistsTab.Visibility = AlbumsTab.Visibility = PlaylistsTab.Visibility = ImportTab.Visibility = Visibility.Collapsed;
}
else
{
WindowState = WindowState.Normal;
WindowStyle = WindowStyle.SingleBorderWindow;
ChangeTabs(Menu.Playlists);
ShowControlsBox();
TracksTab.Visibility = ArtistsTab.Visibility = AlbumsTab.Visibility = PlaylistsTab.Visibility = ImportTab.Visibility = Visibility.Visible;
}
break;
}
@ -798,7 +839,7 @@ namespace FRESHMusicPlayer
TrackingHandler?.Close();
ConfigurationHandler.Write(App.Config);
Library.Database?.Dispose();
progressTimer.Dispose();
ProgressTimer.Dispose();
watcher.Dispose();
WritePersistence();
}
@ -817,12 +858,12 @@ namespace FRESHMusicPlayer
private void Window_Activated(object sender, EventArgs e)
{
progressTimer.Interval = 100;
ProgressTimer.Interval = 100;
}
private void Window_Deactivated(object sender, EventArgs e)
{
progressTimer.Interval = 1000;
ProgressTimer.Interval = 1000;
}
}
}

View file

@ -0,0 +1,61 @@
<Page x:Class="FRESHMusicPlayer.Pages.FullscreenPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resx = "clr-namespace:FRESHMusicPlayer.Properties"
xmlns:local="clr-namespace:FRESHMusicPlayer.Pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="FullscreenPage" Unloaded="Page_Unloaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Rectangle Fill="Transparent" Height="50" Grid.Row="0" Grid.ColumnSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/>
<Rectangle Fill="Transparent" Height="50" Grid.Row="2" Grid.ColumnSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/>
<Rectangle Fill="Transparent" Width="50" Grid.Column="0" Grid.RowSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/>
<Rectangle Fill="Transparent" Width="50" Grid.Column="2" Grid.RowSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/>
<Viewbox Stretch="Uniform" Panel.ZIndex="2" Grid.Row="1" Grid.Column="1">
<DockPanel LastChildFill="False" Width="700" Height="350">
<Image Source="https://royce551.github.io/assets/images/fmp/fullfmplogo.png" DockPanel.Dock="Top" HorizontalAlignment="Left" Width="100" Margin="10,0,0,0"/>
<Grid DockPanel.Dock="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="CoverArtArea" Width="5"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image x:Name="CoverArtBox" Margin="-64,10,5,0" VerticalAlignment="Top" Height="64" Width="64" HorizontalAlignment="Right" RenderOptions.BitmapScalingMode="HighQuality">
<Image.ToolTip>
<ToolTip>
<Image x:Name="CoverArtBoxToolTip" Width="450" Height="450" RenderOptions.BitmapScalingMode="HighQuality"/>
</ToolTip>
</Image.ToolTip>
</Image>
<TextBlock x:Name="TitleLabel" HorizontalAlignment="Stretch" Margin="5,5,40,0" TextWrapping="NoWrap" Text="{x:Static resx:Resources.MAINWINDOW_NOTHINGPLAYING}" VerticalAlignment="Top" FontWeight="Bold" FontSize="22" Grid.Column="1" Height="30" Foreground="{StaticResource PrimaryTextColor}" TextTrimming="CharacterEllipsis" Grid.ColumnSpan="2" Panel.ZIndex="0"/>
<Slider x:Name="ProgressBar" Grid.Column="1" IsEnabled="False" HorizontalAlignment="Stretch" Margin="37,54,45,0" VerticalAlignment="Top" Height="21" Style="{StaticResource Progress_Slider}" Value="9.8"/>
<TextBlock x:Name="ProgressIndicator1" Grid.Column="1" Margin="5,56,0,0" TextWrapping="NoWrap" Text="10:00" Foreground="{StaticResource SecondaryTextColor}" Height="15" VerticalAlignment="Top" HorizontalAlignment="Left" Width="28"/>
<TextBlock x:Name="ProgressIndicator2" Grid.Column="1" Margin="0,56,0,0" TextWrapping="NoWrap" Text="10:00" Foreground="{StaticResource SecondaryTextColor}" Height="15" VerticalAlignment="Top" HorizontalAlignment="Right" Width="40"/>
<TextBlock x:Name="ArtistLabel" HorizontalAlignment="Stretch" Margin="5,35,10,0" TextWrapping="NoWrap" Text="{x:Static resx:Resources.MAINWINDOW_NOTHINGPLAYING}" VerticalAlignment="Top" Grid.Column="1" Height="20" Foreground="{StaticResource SecondaryTextColor}" TextTrimming="CharacterEllipsis"/>
</Grid>
</DockPanel>
</Viewbox>
<Image x:Name="BackgroundCoverArtBox" HorizontalAlignment="Stretch" Grid.RowSpan="3" Grid.ColumnSpan="3" Grid.Row="0" VerticalAlignment="Stretch" RenderOptions.BitmapScalingMode="LowQuality" Panel.ZIndex="0" Stretch="UniformToFill" Margin="0" >
<Image.Effect>
<BlurEffect Radius="30" KernelType="Gaussian"/>
</Image.Effect>
</Image>
<Rectangle x:Name="CoverArtOverlay" Fill="{StaticResource ForegroundColor}" Grid.RowSpan="3" Grid.ColumnSpan="3" Grid.Row="0" Opacity="0.55"/>
</Grid>
</Page>

View file

@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WinForms = System.Windows.Forms;
namespace FRESHMusicPlayer.Pages
{
/// <summary>
/// Interaction logic for FullscreenPage.xaml
/// </summary>
public partial class FullscreenPage : Page
{
private readonly MainWindow window;
public FullscreenPage(MainWindow window)
{
this.window = window;
InitializeComponent();
window.HideControlsBox();
window.Player.SongStopped += Player_SongStopped;
window.Player.SongChanged += Player_SongChanged;
window.ProgressTimer.Tick += ProgressTimer_Tick;
Player_SongChanged(null, EventArgs.Empty);
}
private void ProgressTimer_Tick(object sender, EventArgs e)
{
var time = window.Player.CurrentTime;
ProgressIndicator1.Text = time.ToString(@"mm\:ss");
if (App.Config.ShowRemainingProgress) ProgressIndicator2.Text
= $"-{TimeSpan.FromSeconds(time.TotalSeconds - Math.Floor(window.Player.CurrentBackend.TotalTime.TotalSeconds)):mm\\:ss}";
if (App.Config.ShowTimeInWindow) Title = $"{time:mm\\:ss}/{window.Player.CurrentBackend.TotalTime:mm\\:ss} | {MainWindow.WindowName}";
ProgressBar.Value = time.TotalSeconds;
}
private void Player_SongChanged(object sender, EventArgs e)
{
var CurrentTrack = window.Player.CurrentBackend.Metadata;
Title = $"{string.Join(", ", CurrentTrack.Artists)} - {CurrentTrack.Title} | {MainWindow.WindowName}";
TitleLabel.Text = CurrentTrack.Title;
ArtistLabel.Text = string.Join(", ", CurrentTrack.Artists) == "" ? Properties.Resources.MAINWINDOW_NOARTIST : string.Join(", ", CurrentTrack.Artists);
ProgressBar.Maximum = window.Player.CurrentBackend.TotalTime.TotalSeconds;
if (window.Player.CurrentBackend.TotalTime.TotalSeconds != 0) ProgressIndicator2.Text = window.Player.CurrentBackend.TotalTime.ToString(@"mm\:ss");
else ProgressIndicator2.Text = "∞";
if (CurrentTrack.CoverArt is null)
{
var file = window.GetCoverArtFromDirectory();
if (file != null)
{
CoverArtBox.Source = BitmapFrame.Create(file, BitmapCreateOptions.None, BitmapCacheOption.None);
SetCoverArtVisibility(true);
}
else
{
CoverArtBox.Source = null;
SetCoverArtVisibility(false);
}
}
else
{
CoverArtBox.Source = BackgroundCoverArtBox.Source = BitmapFrame.Create(new MemoryStream(CurrentTrack.CoverArt), BitmapCreateOptions.None, BitmapCacheOption.None);
SetCoverArtVisibility(true);
}
}
public void SetCoverArtVisibility(bool mode)
{
if (!mode) CoverArtArea.Width = new GridLength(5);
else CoverArtArea.Width = new GridLength(75);
}
private void Player_SongStopped(object sender, EventArgs e)
{
TitleLabel.Text = ArtistLabel.Text = Properties.Resources.MAINWINDOW_NOTHINGPLAYING;
CoverArtBox.Source = null;
SetCoverArtVisibility(false);
}
private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
{
if (window.IsControlsBoxVisible) window.HideControlsBox();
else window.ShowControlsBox();
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
window.Player.SongStopped -= Player_SongStopped;
window.Player.SongChanged -= Player_SongChanged;
window.ProgressTimer.Tick -= ProgressTimer_Tick;
}
}
}

View file

@ -100,6 +100,15 @@ namespace FRESHMusicPlayer.Utilities
sb.Children.Add(doubleAnimation);
return sb;
}
public static Storyboard GetThicknessAnimation(Thickness from, Thickness to, TimeSpan duration, PropertyPath path, IEasingFunction easingFunction = null)
{
var sb = new Storyboard();
var thicknessAnimation = new ThicknessAnimation(from, to, duration);
if (easingFunction != null) thicknessAnimation.EasingFunction = easingFunction;
Storyboard.SetTargetProperty(thicknessAnimation, path);
sb.Children.Add(thicknessAnimation);
return sb;
}
public static Task BeginStoryboardAsync(this Storyboard storyboard, FrameworkElement containingObject)
{
var tcs = new TaskCompletionSource<bool>();