Queue management fixes and stability improvements

This commit is contained in:
Royce551 2020-10-17 12:31:13 -05:00
parent bcc9b3e0c6
commit 4842fc007d
5 changed files with 45 additions and 71 deletions

View file

@ -1,27 +1,10 @@
using FRESHMusicPlayer;
using FRESHMusicPlayer.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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 ATL;
using FRESHMusicPlayer.Handlers;
using FRESHMusicPlayer.Handlers.Notifications;
using System.Threading;
using System.ComponentModel;
using System.Windows.Shell;
using System.Diagnostics;
using LiteDB;
using FRESHMusicPlayer.Utilities;
namespace FRESHMusicPlayer.Pages.Library
{
@ -199,18 +182,15 @@ namespace FRESHMusicPlayer.Pages.Library
private void QueueAllButton_Click(object sender, RoutedEventArgs e)
{
foreach (SongEntry entry in TracksPanel.Items)
{
MainWindow.Player.AddQueue(entry.FilePath);
}
string[] tracks = TracksPanel.Items.OfType<SongEntry>().Select(x => x.FilePath).ToArray(); // avoids firing queue changed event too much
MainWindow.Player.AddQueue(tracks);
}
private void PlayAllButton_Click(object sender, RoutedEventArgs e)
{
foreach (SongEntry entry in TracksPanel.Items)
{
MainWindow.Player.AddQueue(entry.FilePath);
}
MainWindow.Player.ClearQueue();
string[] tracks = TracksPanel.Items.OfType<SongEntry>().Select(x => x.FilePath).ToArray(); // avoids firing queue changed event too much
MainWindow.Player.AddQueue(tracks);
MainWindow.Player.PlayMusic();
}
}

View file

@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="344" MouseEnter="UserControl_MouseEnter" MouseLeave="UserControl_MouseLeave">
d:DesignHeight="40" d:DesignWidth="344" MouseEnter="UserControl_MouseEnter" MouseLeave="UserControl_MouseLeave" MouseLeftButtonDown="UserControl_MouseLeftButtonDown">
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>

View file

@ -53,5 +53,14 @@ namespace FRESHMusicPlayer.Pages
}
private void DeleteButtonClick(object sender, MouseButtonEventArgs e) => MainWindow.Player.RemoveQueue(Index);
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
MainWindow.Player.QueuePosition = Index;
MainWindow.Player.PlayMusic();
}
}
}
}

View file

@ -1,26 +1,14 @@
using ATL;
using FRESHMusicPlayer;
using ATL.Playlist;
using FRESHMusicPlayer.Handlers.Notifications;
using FRESHMusicPlayer.Utilities;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
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 FRESHMusicPlayer.Utilities;
using Microsoft.Win32;
using ATL.Playlist;
using FRESHMusicPlayer.Handlers.Notifications;
using System.IO;
using System.Threading;
using Windows.System.Preview;
namespace FRESHMusicPlayer.Pages
{
@ -31,6 +19,7 @@ namespace FRESHMusicPlayer.Pages
{
private bool taskisrunning;
private readonly Queue<List<string>> displayqueue = new Queue<List<string>>();
private int currentIndex = 0;
public QueueManagement()
{
InitializeComponent();
@ -46,14 +35,10 @@ namespace FRESHMusicPlayer.Pages
var list = displayqueue.Dequeue();
var nextlength = 0;
int number = 1;
AddTrackButton.IsEnabled = false;
AddPlaylistButton.IsEnabled = false;
ClearQueueButton.IsEnabled = false;
SetControlEnabled(false);
QueueList.Visibility = Visibility.Hidden;
QueueList.Items.Clear();
await Task.Run(() =>
{
try
{
foreach (var song in list)
{
@ -66,22 +51,15 @@ namespace FRESHMusicPlayer.Pages
Track track = new Track(song);
entry = Dispatcher.Invoke(() => new QueueEntry(track.Artist, track.Album, track.Title, number.ToString(), number - 1));
}
if (entry.Index + 1 == MainWindow.Player.QueuePosition) Dispatcher.Invoke(() => entry.BringIntoView());
Dispatcher.Invoke(() => QueueList.Items.Add(entry));
if (entry.Index + 1 == MainWindow.Player.QueuePosition) currentIndex = entry.Index;
if (MainWindow.Player.QueuePosition < number) nextlength += dbTrack.Length;
number++;
}
}
catch (InvalidOperationException)
{
GetResults();
// TODO: This occurs when too many tracks are enqueued at once. Don't really know how to permanently fix this so this'll work for now...
}
});
if (QueueList.Items.Count > 0) (QueueList.Items[currentIndex] as QueueEntry).BringIntoView();
RemainingTimeLabel.Text = Properties.Resources.QUEUEMANAGEMENT_REMAININGTIME + new TimeSpan(0, 0, 0, nextlength).ToString(@"hh\:mm\:ss");
AddTrackButton.IsEnabled = true;
AddPlaylistButton.IsEnabled = true;
ClearQueueButton.IsEnabled = true;
SetControlEnabled(true);
QueueList.Visibility = Visibility.Visible;
taskisrunning = false;
if (displayqueue.Count != 0) GetResults();
@ -93,6 +71,12 @@ namespace FRESHMusicPlayer.Pages
GetResults();
}
}
private void SetControlEnabled(bool enabled)
{
AddTrackButton.IsEnabled = enabled;
AddPlaylistButton.IsEnabled = enabled;
ClearQueueButton.IsEnabled = enabled;
}
private void Player_QueueChanged(object sender, EventArgs e)
{

View file

@ -110,6 +110,7 @@ namespace FRESHMusicPlayer.Utilities
public static void Nuke()
{
MainWindow.Libraryv2.GetCollection<DatabaseTrack>("tracks").DeleteAll();
MainWindow.Libraryv2.GetCollection<DatabasePlaylist>("playlists").DeleteAll();
MainWindow.NotificationHandler.Add(new Notification
{
HeaderText = "Nuke successful",