Queue management improvements

This commit is contained in:
Royce551 2020-11-07 19:14:32 -06:00
parent d90cfb0613
commit a22458ab4c
3 changed files with 29 additions and 17 deletions

View file

@ -83,7 +83,7 @@
</Grid.ColumnDefinitions>
<Image x:Name="CoverArtBox" Margin="-64,10,5,0" VerticalAlignment="Top" Height="64" Width="64" HorizontalAlignment="Right" RenderOptions.BitmapScalingMode="HighQuality" MouseLeftButtonDown="TrackTitle_MouseLeftButtonDown" MouseRightButtonDown="TrackTitle_MouseRightButtonDown" Cursor="Hand"/>
<TextBlock x:Name="TitleLabel" HorizontalAlignment="Stretch" Margin="5,5,10,0" TextWrapping="NoWrap" Text="Nothing Playing" VerticalAlignment="Top" FontWeight="Bold" FontSize="22" Grid.Column="1" Height="30" Foreground="{StaticResource PrimaryTextColor}" TextTrimming="CharacterEllipsis" MouseLeftButtonDown="TrackTitle_MouseLeftButtonDown" MouseRightButtonDown="TrackTitle_MouseRightButtonDown" Cursor="Hand"/>
<Slider x:Name="ProgressBar" Grid.Column="1" HorizontalAlignment="Stretch" Margin="37,54,45,0" VerticalAlignment="Top" Height="21" Style="{StaticResource Progress_Slider}" Value="9.8" Thumb.DragStarted="ProgressBar_DragStarted" Thumb.DragCompleted="ProgressBar_DragCompleted" ValueChanged="ProgressBar_ValueChanged" IsMoveToPointEnabled="True"/>
<Slider x:Name="ProgressBar" Grid.Column="1" HorizontalAlignment="Stretch" Margin="37,54,45,0" VerticalAlignment="Top" Height="21" Style="{StaticResource Progress_Slider}" Value="9.8" Thumb.DragStarted="ProgressBar_DragStarted" Thumb.DragCompleted="ProgressBar_DragCompleted" ValueChanged="ProgressBar_ValueChanged" IsMoveToPointEnabled="True" MouseLeftButtonUp="ProgressBar_MouseLeftButtonUp"/>
<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,0,10,13" TextWrapping="NoWrap" Text="10:00" Foreground="{StaticResource SecondaryTextColor}" Height="15" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="30"/>
<TextBlock x:Name="ArtistLabel" HorizontalAlignment="Stretch" Margin="5,35,10,0" TextWrapping="NoWrap" Text="Nothing Playing" VerticalAlignment="Top" Grid.Column="1" Height="20" Foreground="{StaticResource SecondaryTextColor}" TextTrimming="CharacterEllipsis"/>

View file

@ -6,11 +6,9 @@ using FRESHMusicPlayer.Handlers.Configuration;
using FRESHMusicPlayer.Handlers.Notifications;
using FRESHMusicPlayer.Utilities;
using LiteDB;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -345,10 +343,18 @@ namespace FRESHMusicPlayer
private void StopButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => StopMethod();
private void NextTrackButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => NextTrackMethod();
private bool isDragging = false;
private void ProgressBar_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) => isDragging = true;
private void ProgressBar_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
{
isDragging = true;
progressTimer.Stop();
}
private void ProgressBar_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
if (Player.Playing) Player.RepositionMusic((int)ProgressBar.Value);
if (Player.Playing)
{
Player.RepositionMusic((int)ProgressBar.Value);
progressTimer.Start();
}
isDragging = false;
}
@ -360,6 +366,11 @@ namespace FRESHMusicPlayer
ProgressTick();
}
}
private void ProgressBar_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (Player.Playing && !isDragging) Player.RepositionMusic((int)ProgressBar.Value);
ProgressTick();
}
private void VolumeBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Player.CurrentVolume = (float)(VolumeBar.Value / 100);
@ -614,5 +625,7 @@ namespace FRESHMusicPlayer
VolumeBar.Value += e.Delta / 100 * 3;
if (Player.Playing && Player.CurrentVolume >= 0 && Player.CurrentVolume <= 1) Player.UpdateSettings();
}
}
}

View file

@ -1,11 +1,11 @@
using ATL;
using ATL.Playlist;
using ATL.Playlist;
using FRESHMusicPlayer.Handlers.Notifications;
using FRESHMusicPlayer.Utilities;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@ -25,11 +25,12 @@ namespace FRESHMusicPlayer.Pages
InitializeComponent();
PopulateList();
MainWindow.Player.QueueChanged += Player_QueueChanged;
MainWindow.Player.SongStopped += Player_SongStopped;
}
public void PopulateList() // God have mercy on future me/others.
public void PopulateList()
{
displayqueue.Enqueue(MainWindow.Player.Queue);
displayqueue.Enqueue(MainWindow.Player.Queue); // Queue of pending queue management updates
async void GetResults()
{
var list = displayqueue.Dequeue();
@ -37,7 +38,7 @@ namespace FRESHMusicPlayer.Pages
int number = 1;
SetControlEnabled(false);
QueueList.Items.Clear();
await Task.Run(() =>
await Task.Run(() => // Display controls
{
foreach (var song in list)
{
@ -48,10 +49,11 @@ namespace FRESHMusicPlayer.Pages
Dispatcher.Invoke(() => QueueList.Items.Add(entry));
if (entry.Index + 1 == MainWindow.Player.QueuePosition) currentIndex = entry.Index;
if (MainWindow.Player.QueuePosition < number) nextlength += dbTrack.Length;
if (number % 25 == 0) Thread.Sleep(1); // Apply a slight delay once in a while to let the UI catch up
number++;
}
});
if (QueueList.Items.Count > 0) (QueueList.Items[currentIndex] as QueueEntry).BringIntoView();
if (QueueList.Items.Count > 0) (QueueList.Items[currentIndex] as QueueEntry).BringIntoView(); // Bring current track into view
RemainingTimeLabel.Text = Properties.Resources.QUEUEMANAGEMENT_REMAININGTIME + new TimeSpan(0, 0, 0, nextlength).ToString(@"hh\:mm\:ss");
SetControlEnabled(true);
taskisrunning = false;
@ -70,15 +72,12 @@ namespace FRESHMusicPlayer.Pages
AddPlaylistButton.IsEnabled = enabled;
ClearQueueButton.IsEnabled = enabled;
}
private void Player_QueueChanged(object sender, EventArgs e)
{
PopulateList();
}
private void Player_QueueChanged(object sender, EventArgs e) => PopulateList();
private void Player_SongStopped(object sender, EventArgs e) => PopulateList();
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
MainWindow.Player.QueueChanged -= Player_QueueChanged;
MainWindow.Player.SongStopped -= Player_SongStopped;
QueueList.Items.Clear();
}