/// <summary> /// Handles everything related to drag drop /// </summary> /// <param name="tracks">The file paths that were dropped</param> /// <param name="player">An instance of the Player</param> /// <param name="library">An instance of the Library</param> /// <param name="enqueue">Whether to enqueue the tracks that were dropped</param> /// <param name="import">Whether to import the tracks that were dropped</param> /// <param name="clearqueue">Whether to clear the queue before handling everything else</param> public static async void DoDragDrop(string[] tracks, Player player, GUILibrary library, bool enqueue = true, bool import = true, bool clearqueue = true) { if (clearqueue) player.Queue.Clear(); if (tracks.Any(x => Directory.Exists(x))) { foreach (var track in tracks) { if (Directory.Exists(track)) { string[] paths = Directory.EnumerateFiles(tracks[0], "*", SearchOption.AllDirectories) .Where(name => name.EndsWith(".mp3") || name.EndsWith(".wav") || name.EndsWith(".m4a") || name.EndsWith(".ogg") || name.EndsWith(".flac") || name.EndsWith(".aiff") || name.EndsWith(".wma") || name.EndsWith(".aac")).ToArray(); if (enqueue) player.Queue.Add(paths); if (import) await Task.Run(() => library.Import(paths)); } else { if (enqueue) player.Queue.Add(track); if (import) await Task.Run(() => library.Import(track)); } } } else { if (enqueue) player.Queue.Add(tracks); if (import) await Task.Run(() => library.Import(tracks)); } }
public PlaylistEntry(string playlist, string path, GUILibrary library, PlaylistManagement window, Tab selectedMenu) { this.library = library; this.window = window; this.selectedMenu = selectedMenu; InitializeComponent(); if (path is null) { trackExists = false; } TitleLabel.Text = playlist; if (selectedMenu == Tab.Artists) { AddThingButton.Content = $"+ {Properties.Resources.TAGEDITOR_ARTIST}"; } else { AddThingButton.Content = $"+ {Properties.Resources.TRACKINFO_ALBUM}"; } this.playlist = playlist; this.path = path; CheckIfPlaylistExists(); }
public TagEditor(List <string> filePaths, Player player = null, GUILibrary library = null) { this.player = player ?? new Player(); this.library = library; InitializeComponent(); httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("FRESHMusicPlayer/8.2.0 (https://github.com/Royce551/FRESHMusicPlayer)"); FilePaths = filePaths; player.SongChanged += Player_SongChanged; InitFields(); }
public SongEntry(string filePath, string artist, string album, string title, Player player, NotificationHandler notificationHandler, GUILibrary library) { this.player = player; this.notificationHandler = notificationHandler; this.library = library; InitializeComponent(); FilePath = filePath; ArtistAlbumLabel.Text = $"{artist} ・ {album}"; TitleLabel.Text = title; Title = title; }
public async void Initialize(string[] initialFile) { LoggingHandler.Log("Reading library..."); LiteDatabase library; try { #if DEBUG // allow multiple instances of FMP in debug (at the expense of stability with heavy library use) library = new LiteDatabase($"Filename=\"{Path.Combine(App.DataFolderLocation, "database.fdb2")}\";Connection=shared"); #else library = new LiteDatabase(Path.Combine(App.DataFolderLocation, "database.fdb2")); #endif Library = new GUILibrary(library, NotificationHandler, Dispatcher); } catch (IOException) // library is *probably* being used by another FMP, write initial files, hopefully existing FMP will pick them up { File.WriteAllLines(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "instance"), initialFile ?? Array.Empty <string>()); Application.Current.Shutdown(); return; // stop initial files from trying to load } watcher.Filter = "instance"; watcher.IncludeSubdirectories = false; watcher.EnableRaisingEvents = true; watcher.Changed += (object sender, FileSystemEventArgs args) => { Dispatcher.Invoke(async() => { var files = File.ReadAllLines(args.FullPath); if (files.Length != 0) // user wants to play a file { Player.Queue.Clear(); Player.Queue.Add(files); await Player.PlayAsync(); } else // user might've forgotten fmp is open, let's flash { Activate(); Topmost = true; Topmost = false; } File.Delete(args.FullPath); }); }; LoggingHandler.Log("Ready to go!"); if (initialFile != null) { Player.Queue.Add(initialFile); await Player.PlayAsync(); } }
public PlaylistManagement(GUILibrary library, NotificationHandler notificationHandler, Menu selectedMenu, string track = null) { this.library = library; this.notificationHandler = notificationHandler; this.selectedMenu = selectedMenu; InitializeComponent(); if (track != null) { EditingHeader.Text = string.Format(Properties.Resources.PLAYLISTMANAGEMENT_HEADER, Path.GetFileName(track)); } else { EditingHeader.Visibility = Visibility.Collapsed; } this.track = track; InitFields(); }
public MainWindow(Player player, string[] initialFile = null) { LoggingHandler.Log("Starting main window..."); Player = player; InitializeComponent(); Player.SongChanged += Player_SongChanged; Player.SongStopped += Player_SongStopped; Player.SongException += Player_SongException; NotificationHandler.NotificationInvalidate += NotificationHandler_NotificationInvalidate; progressTimer = new WinForms.Timer { Interval = 100 }; progressTimer.Tick += ProgressTimer_Tick; LoggingHandler.Log("Reading library..."); LiteDatabase library; try { #if DEBUG // allow multiple instances of FMP in debug library = new LiteDatabase($"Filename=\"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "database.fdb2")}\";Connection=shared"); #elif !DEBUG library = new LiteDatabase(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "database.fdb2")); #endif Library = new GUILibrary(library, NotificationHandler); } catch (IOException) // library is *probably* being used by another FMP. { File.WriteAllLines(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "instance"), initialFile ?? Array.Empty <string>()); Application.Current.Shutdown(); } watcher.Filter = "instance"; watcher.IncludeSubdirectories = false; watcher.EnableRaisingEvents = true; watcher.Changed += (object sender, FileSystemEventArgs args) => { Dispatcher.Invoke(() => { var files = File.ReadAllLines(args.FullPath); if (files.Length != 0) { player.Queue.Clear(); player.Queue.Add(files); player.PlayMusic(); } File.Delete(args.FullPath); Activate(); Topmost = true; Topmost = false; }); }; LoggingHandler.Log("Ready to go!"); if (initialFile != null) { Player.Queue.Add(initialFile); Player.PlayMusic(); } }