private void Player_SongException(object sender, PlaybackExceptionEventArgs e) { NotificationHandler.Add(new Notification { ContentText = string.Format(Properties.Resources.MAINWINDOW_PLAYBACK_ERROR_DETAILS, e.Details), IsImportant = true, DisplayAsToast = true, Type = NotificationType.Failure }); Player.NextSong(); }
private async void PlayButtonClick(object sender, MouseButtonEventArgs e) { if (FilePath.StartsWith("http") || File.Exists(FilePath)) { if (player.FileLoaded) { player.Queue.Clear(); } await player.PlayAsync(FilePath); } else { notificationHandler.Add(new Handlers.Notifications.Notification { ContentText = string.Format(Properties.Resources.NOTIFICATION_FILEGONE, FilePath), ButtonText = "Remove from library", OnButtonClicked = () => { library.Remove(FilePath); ((ListBox)Parent).Items.Remove(this); return(true); }, Type = NotificationType.Failure }); } }
private void ImportButton_Click(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Playlist Files|*.xspf;*.asx;*.wax;*.wvx;*.b4s;*.m3u;*.m3u8;*.pls;*.smil;*.smi;*.zpl;"; if (dialog.ShowDialog() == true) { IPlaylistIO reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(dialog.FileName); foreach (string s in reader.FilePaths) { if (!File.Exists(s)) { notificationHandler.Add(new Notification { ContentText = string.Format(Properties.Resources.NOTIFICATION_COULD_NOT_IMPORT_PLAYLIST, s), IsImportant = true, DisplayAsToast = true, Type = NotificationType.Failure }); continue; } library.AddTrackToPlaylist(Path.GetFileNameWithoutExtension(dialog.FileName), s); } } InitFields(); }
// Systemwide logic public void ProcessSettings(bool initialize = false) { if (initialize) { VolumeBar.Value = App.Config.Volume; ChangeTabs(App.Config.CurrentMenu); } if (App.Config.PlaybackTracking) { TrackingHandler = new PlaytimeTrackingHandler(this); } else if (TrackingHandler != null) { TrackingHandler?.Close(); TrackingHandler = null; } var version = Assembly.GetEntryAssembly().GetName().Version.ToString(); if (version != App.Config.LastRecordedVersion && App.Config.LastRecordedVersion != null) { NotificationHandler.Add(new Notification { ContentText = string.Format(Properties.Resources.NOTIFICATION_UPTODATE, version), ButtonText = Properties.Resources.NOTIFICATION_UPTODATE_CHANGELOG, Type = NotificationType.Success, OnButtonClicked = () => { Process.Start("https://github.com/royce551/freshmusicplayer/releases/latest"); return(true); } }); } App.Config.LastRecordedVersion = version; }
public override void Import(List <string> tracks) { var notification = new Notification { ContentText = $"Importing {tracks.Count} tracks" }; dispatcher.Invoke(() => notificationHandler.Add(notification)); base.Import(tracks); dispatcher.Invoke(() => { notificationHandler.Remove(notification); if (RaiseLibraryChanged) { LibraryChanged?.Invoke(null, EventArgs.Empty); } }); }
public override void Nuke(bool nukePlaylists = true) { base.Nuke(nukePlaylists); notificationHandler.Add(new Notification { ContentText = Properties.Resources.NOTIFICATION_CLEARSUCCESS, Type = NotificationType.Success }); }
private async void Player_SongException(object sender, PlaybackExceptionEventArgs e) { if (!InFullscreen) { Mouse.OverrideCursor = null; } NotificationHandler.Add(new Notification { ContentText = string.Format(Properties.Resources.MAINWINDOW_PLAYBACK_ERROR_DETAILS, e.Details), IsImportant = true, DisplayAsToast = true, Type = NotificationType.Failure }); await Player.NextAsync(); }
public async Task PerformAutoImport() { if (App.Config.AutoImportPaths.Count <= 0) { return; // not really needed but prevents going through unneeded } // effort (and showing the notification) var notification = new Notification { ContentText = Properties.Resources.NOTIFICATION_SCANNING }; NotificationHandler.Add(notification); var filesToImport = new List <string>(); var library = Library.Read(); await Task.Run(() => { foreach (var folder in App.Config.AutoImportPaths) { var files = Directory.EnumerateFiles(folder, "*", 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(); foreach (var file in files) { if (!library.Select(x => x.Path).Contains(file)) { filesToImport.Add(file); } } } Library.Import(filesToImport); }); NotificationHandler.Remove(notification); }
public async Task UpdateApp(bool useDeltaPatching = true, bool forceUpdate = false) { if (App.Config.UpdateMode == UpdateMode.Manual && !forceUpdate) { return; } // Updater not present, probably standalone if (!File.Exists(Path.Combine(rootPath, "Update.exe"))) { return; } App.Config.UpdatesLastChecked = DateTime.Now; var notification = new Notification(); UpdateManager mgr = await UpdateManager.GitHubUpdateManager("https://github.com/Royce551/FRESHMusicPlayer"); try { UpdateInfo updateInfo = await mgr.CheckForUpdate(!useDeltaPatching); if (updateInfo.CurrentlyInstalledVersion == null) { return; // Standalone version of FMP, don't bother } if (updateInfo.ReleasesToApply.Count == 0) { return; // No updates to apply, don't bother } notification.ContentText = Properties.Resources.NOTIFICATION_INSTALLINGUPDATE; notificationHandler.Add(notification); await mgr.DownloadReleases(updateInfo.ReleasesToApply); await mgr.ApplyReleases(updateInfo); if (App.Config.UpdateMode == UpdateMode.Prompt) { notification.ContentText = Properties.Resources.NOTIFICATION_UPDATEREADY; notification.ButtonText = Properties.Resources.SETTINGS_RESTART_NOW; notification.Type = NotificationType.Success; notification.OnButtonClicked = () => { RestartApp(); return(true); }; notificationHandler.Update(notification); } else { RestartApp(); } } catch (Exception e) { if (useDeltaPatching) { await UpdateApp(false); return; } notification.ContentText = string.Format(Properties.Resources.NOTIFICATION_UPDATEERROR, e.Message); notification.Type = NotificationType.Failure; notificationHandler.Update(notification); } finally { mgr?.Dispose(); } }
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) { if (!(e.OriginalSource is TextBox || e.OriginalSource is ListBoxItem) || Keyboard.IsKeyDown(Key.LeftCtrl)) { switch (e.Key) { case Key.Q: ShowAuxilliaryPane(Pane.Settings, 335); break; case Key.A: ChangeTabs(Tab.Tracks); break; case Key.S: ChangeTabs(Tab.Artists); break; case Key.D: ChangeTabs(Tab.Albums); break; case Key.F: ChangeTabs(Tab.Playlists); break; case Key.G: ChangeTabs(Tab.Import); break; case Key.E: ShowAuxilliaryPane(Pane.Search, 335); break; case Key.R: ShowAuxilliaryPane(Pane.TrackInfo, 235, true); break; case Key.W: ShowAuxilliaryPane(Pane.QueueManagement, 335); break; case Key.Space: PlayPauseMethod(); break; case Key.P: var printdlg = new PrintDialog(); var result = printdlg.ShowDialog(); if (result != null && result != false) { printdlg.PrintVisual(new PrintOutput(this, CurrentTrack.Album), CurrentTrack.Album); } break; } } switch (e.Key) { case Key.F1: Process.Start("https://royce551.github.io/FRESHMusicPlayer/docs/index.html"); break; case Key.F11: if (CurrentTab != Tab.Fullscreen) { ChangeTabs(Tab.Fullscreen); } else { ChangeTabs(Tab.Playlists); } break; case Key.F12: NotificationHandler.Add(new Notification { ContentText = "Debug Tools" }); NotificationHandler.Add(new Notification { ButtonText = "Garbage Collect", OnButtonClicked = () => { GC.Collect(2); return(false); } }); NotificationHandler.Add(new Notification { ButtonText = "Throw exception", OnButtonClicked = () => { throw new Exception("Exception for debugging"); } }); NotificationHandler.Add(new Notification { ButtonText = "Make FMP topmost", OnButtonClicked = () => { Topmost = !Topmost; return(false); } }); break; } }