mirror of
https://github.com/Royce551/FRESHMusicPlayer.git
synced 2025-01-22 19:02:19 -05:00
Queue management fixes and stability improvements
This commit is contained in:
parent
bcc9b3e0c6
commit
4842fc007d
5 changed files with 45 additions and 71 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,42 +35,31 @@ 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)
|
||||
{
|
||||
foreach (var song in list)
|
||||
if (displayqueue.Count > 1) break;
|
||||
QueueEntry entry;
|
||||
var dbTrack = MainWindow.Libraryv2.GetCollection<DatabaseTrack>("tracks").FindOne(x => song == x.Path);
|
||||
if (dbTrack != null) entry = Dispatcher.Invoke(() => new QueueEntry(dbTrack.Artist, dbTrack.Album, dbTrack.Title, number.ToString(), number - 1));
|
||||
else
|
||||
{
|
||||
if (displayqueue.Count > 1) break;
|
||||
QueueEntry entry;
|
||||
var dbTrack = MainWindow.Libraryv2.GetCollection<DatabaseTrack>("tracks").FindOne(x => song == x.Path);
|
||||
if (dbTrack != null) entry = Dispatcher.Invoke(() => new QueueEntry(dbTrack.Artist, dbTrack.Album, dbTrack.Title, number.ToString(), number - 1));
|
||||
else
|
||||
{
|
||||
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 (MainWindow.Player.QueuePosition < number) nextlength += dbTrack.Length;
|
||||
number++;
|
||||
Track track = new Track(song);
|
||||
entry = Dispatcher.Invoke(() => new QueueEntry(track.Artist, track.Album, track.Title, number.ToString(), number - 1));
|
||||
}
|
||||
}
|
||||
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...
|
||||
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++;
|
||||
}
|
||||
});
|
||||
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)
|
||||
{
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue