public void Close()
        {
            LoggingHandler.Log("Closing Discord integration");

            client.ClearPresence();
            client.Dispose();
        }
예제 #2
0
 private void Player_SongChanged(object sender, EventArgs e)
 {
     try
     {
         var track         = new Track(player.FilePath);
         var trackingEntry = new TrackingEntry
         {
             DatePlayed = DateTime.Now,
             Track      = new DatabaseTrack
             {
                 Path        = player.FilePath,
                 Artist      = track.Artist,
                 Title       = track.Title,
                 Album       = track.Album,
                 TrackNumber = track.TrackNumber,
                 Length      = track.Duration
             }
         };
         trackingFile.Entries.Add(trackingEntry);
         LoggingHandler.Log("Playtime Logging: Entry created!");
     }
     catch (Exception ex)
     {
         LoggingHandler.Log($"Playtime Logging: Exception was thrown - {ex}");
         // ignored
     }
 }
예제 #3
0
        void App_Startup(object sender, StartupEventArgs e)
        {
            LoggingHandler.Log("Handling configuration...");

            Config = ConfigurationHandler.Read();
            player = new Player {
                Volume = Config.Volume
            };
            if (Config.Language != "automatic")
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Config.Language);
            }
            ChangeSkin(Config.Theme);

            LoggingHandler.Log("Handling command line args...");

            if (e.Args.Length > 0)
            {
                var args = e.Args.Where(x => x.Contains('.'));
                if (e.Args.Contains("--tageditor"))
                {
                    currentWindow = new TagEditor(args.ToList(), player);
                }
                else
                {
                    currentWindow = new MainWindow(player, args.ToArray());
                }
            }
            else
            {
                currentWindow = new MainWindow(player);
            }
            currentWindow.Show();
        }
예제 #4
0
 public PlaytimeLoggingIntegration(Player player)
 {
     this.player         = player;
     player.SongChanged += Player_SongChanged;
     filePath            = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "Tracking");
     trackingFile        = Read();
     LoggingHandler.Log("Playtime Logging: Starting!");
 }
예제 #5
0
        public void ShowAuxilliaryPane(AuxiliaryPane pane, int width = 235, bool openleft = false)
        {
            LoggingHandler.Log($"Showing pane --> {pane}");
            if (SelectedAuxiliaryPane == pane)
            {
                HideAuxilliaryPane();
                return;
            }
            if (SelectedAuxiliaryPane != AuxiliaryPane.None)
            {
                HideAuxilliaryPane(false);
            }
            switch (pane)
            {
            case AuxiliaryPane.Settings:
                RightFrame.Navigate(new SettingsPage(this));
                break;

            case AuxiliaryPane.QueueManagement:
                RightFrame.Navigate(new QueueManagement(this));
                break;

            case AuxiliaryPane.Search:
                RightFrame.Navigate(new SearchPage(this));
                break;

            case AuxiliaryPane.Notifications:
                RightFrame.Navigate(new NotificationPage(this));
                break;

            case AuxiliaryPane.TrackInfo:
                RightFrame.Navigate(new TrackInfoPage(this));
                break;

            case AuxiliaryPane.Lyrics:
                RightFrame.Navigate(new LyricsPage(this));
                break;

            default:
                return;
            }
            if (!openleft)
            {
                DockPanel.SetDock(RightFrame, Dock.Right);
            }
            else
            {
                DockPanel.SetDock(RightFrame, Dock.Left);
            }
            RightFrame.Visibility = Visibility.Visible;
            var sb = InterfaceUtils.GetDoubleAnimation(0, width, TimeSpan.FromMilliseconds(100), new PropertyPath("Width"));

            sb.Begin(RightFrame);
            SelectedAuxiliaryPane = pane;
            RightFrame.NavigationService.RemoveBackEntry();
        }
        public DiscordIntegration()
        {
            LoggingHandler.Log("Starting Discord integration");

            client = new DiscordRpcClient("656678380283887626");
            client.Initialize();
            client.OnRpcMessage += (sender, e) =>
            {
                LoggingHandler.Log($"Discord: {e.Type}");
            };
        }
        private void Player_SongStopped(object sender, EventArgs e)
        {
            Title           = WindowName;
            TitleLabel.Text = ArtistLabel.Text = Properties.Resources.MAINWINDOW_NOTHINGPLAYING;
            ProgressTimer.Stop();
            CoverArtBox.Source = null;
            SetIntegrations(PlaybackStatus.Stopped);
            SetCoverArtVisibility(false);

            LoggingHandler.Log("Stopping!");
        }
예제 #8
0
        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 void ChangeTabs(Tab tab, string search = null)
        {
            LoggingHandler.Log($"Changing tabs -> {tab}");

            var previousMenu = CurrentTab;

            CurrentTab = tab;
            TextBlock tabLabel;

            switch (CurrentTab)
            {
            case Tab.Tracks:
                ContentFrame.Content = new LibraryPage(this, search);
                tabLabel             = TracksTab;
                break;

            case Tab.Artists:
                ContentFrame.Content = new LibraryPage(this, search);
                tabLabel             = ArtistsTab;
                break;

            case Tab.Albums:
                ContentFrame.Content = new LibraryPage(this, search);
                tabLabel             = AlbumsTab;
                break;

            case Tab.Playlists:
                ContentFrame.Content = new LibraryPage(this, search);
                tabLabel             = PlaylistsTab;
                break;

            case Tab.Import:
                ContentFrame.Content = new ImportPage(this);
                tabLabel             = ImportTab;
                break;

            case Tab.Fullscreen:
                ContentFrame.Content = new FullscreenPage(this, previousMenu);
                tabLabel             = ImportTab;
                break;

            default:
                tabLabel = null;
                break;
            }
            TracksTab.FontWeight = ArtistsTab.FontWeight = AlbumsTab.FontWeight = PlaylistsTab.FontWeight = ImportTab.FontWeight = FontWeights.Normal;
            tabLabel.FontWeight  = FontWeights.Bold;
        }
예제 #10
0
        private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            string logPath  = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\FRESHMusicPlayer\\Logs";
            string fileName = $"\\{DateTime.Now:M.d.yyyy hh mm tt}.txt";

            if (!Directory.Exists(logPath))
            {
                Directory.CreateDirectory(logPath);
            }
            File.WriteAllText(logPath + fileName,
                              $"FRESHMusicPlayer {Assembly.GetEntryAssembly().GetName().Version}\n" +
                              $"{System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}\n" +
                              $"{Environment.OSVersion.VersionString}\n" +
                              $"{e.Exception}");
            var message = string.Format(FRESHMusicPlayer.Properties.Resources.APPLICATION_CRITICALERROR, e.Exception.Message.ToString(), logPath + fileName);

            if (currentWindow is MainWindow maybeWindow)
            {
                try
                {
                    maybeWindow.NotificationHandler.Add(new Handlers.Notifications.Notification
                    {
                        DisplayAsToast  = true,
                        IsImportant     = true,
                        Type            = Handlers.Notifications.NotificationType.Failure,
                        ContentText     = message,
                        ButtonText      = "Open debug log",
                        OnButtonClicked = () =>
                        {
                            System.Diagnostics.Process.Start(logPath);
                            System.Diagnostics.Process.Start(logPath + fileName);
                            return(true);
                        }
                    });
                }
                catch
                {
                    MessageBox.Show(message);
                }
            }
            else
            {
                MessageBox.Show(message);
            }
            LoggingHandler.Log($"There was an unhandled exception:\n{e.Exception}");
            e.Handled = true;
        }
예제 #11
0
        public async Task Initialize()
        {
            LoggingHandler.Log("Starting MPRIS Integration");
            try
            {
                connection = new Connection(Address.Session);
                await connection.ConnectAsync();

                await connection.RegisterObjectAsync(mediaPlayer2);

                await connection.RegisterServiceAsync("org.mpris.MediaPlayer2.FRESHMusicPlayer");
            }
            catch (Exception e)
            {
                LoggingHandler.Log($"MPRIS: {e}");
            }
        }
예제 #12
0
        private void Player_SongChanged(object sender, EventArgs e)
        {
            CurrentTrack        = new Track(Player.FilePath);
            Title               = $"{CurrentTrack.Artist} - {CurrentTrack.Title} | FRESHMusicPlayer";
            TitleLabel.Text     = CurrentTrack.Title;
            ArtistLabel.Text    = CurrentTrack.Artist == "" ? Properties.Resources.MAINWINDOW_NOARTIST : CurrentTrack.Artist;
            ProgressBar.Maximum = Player.CurrentBackend.TotalTime.TotalSeconds;
            if (Player.CurrentBackend.TotalTime.TotalSeconds != 0)
            {
                ProgressIndicator2.Text = Player.CurrentBackend.TotalTime.ToString(@"mm\:ss");
            }
            else
            {
                ProgressIndicator2.Text = "∞";
            }
            SetIntegrations(PlaybackStatus.Playing);
            UpdatePlayButtonState();
            if (CurrentTrack.EmbeddedPictures.Count == 0)
            {
                var file = GetCoverArtFromDirectory();
                if (file != null)
                {
                    CoverArtBox.Source = BitmapFrame.Create(file, BitmapCreateOptions.None, BitmapCacheOption.None);
                    SetCoverArtVisibility(true);
                }
                else
                {
                    CoverArtBox.Source = null;
                    SetCoverArtVisibility(false);
                }
            }
            else
            {
                CoverArtBox.Source = BitmapFrame.Create(new MemoryStream(CurrentTrack.EmbeddedPictures[0].PictureData), BitmapCreateOptions.None, BitmapCacheOption.None);
                SetCoverArtVisibility(true);
            }
            progressTimer.Start();
            if (PauseAfterCurrentTrack && !Player.Paused)
            {
                PlayPauseMethod();
                PauseAfterCurrentTrack = false;
            }

            LoggingHandler.Log("Changing tracks");
        }
예제 #13
0
        public SMTCIntegration(MainWindow window)
        {
            LoggingHandler.Log("Starting SMTC Integration");

            this.window = window;

            var    smtcInterop = (ISystemMediaTransportControlsInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(SystemMediaTransportControls));
            var    wih         = new WindowInteropHelper(window);
            IntPtr hWnd        = wih.Handle;

            smtc = smtcInterop.GetForWindow(hWnd, new Guid("99FA3FF4-1742-42A6-902E-087D41F965EC"));
            smtc.IsPlayEnabled     = true;
            smtc.IsPauseEnabled    = true;
            smtc.IsNextEnabled     = true;
            smtc.IsStopEnabled     = true;
            smtc.IsPreviousEnabled = true;
            smtc.ButtonPressed    += Smtc_ButtonPressed;
        }
예제 #14
0
        public MainWindow(Player player, string[] initialFile = null)
        {
            LoggingHandler.Log("Starting main window...");
            Player = player;
            InitializeComponent();
            Player.SongChanged   += Player_SongChanged;
            Player.SongLoading   += Player_SongLoading;
            Player.SongStopped   += Player_SongStopped;
            Player.SongException += Player_SongException;
            NotificationHandler.NotificationInvalidate += NotificationHandler_NotificationInvalidate;
            ProgressTimer = new WinForms.Timer
            {
                Interval = 100
            };
            ProgressTimer.Tick += ProgressTimer_Tick;

            Initialize(initialFile);
        }
예제 #15
0
        private void ChangeTabs(Menu tab, string search = null)
        {
            LoggingHandler.Log($"Changing tabs -> {tab}");

            SelectedMenu = tab;
            TextBlock tabLabel;

            switch (SelectedMenu)
            {
            case Menu.Tracks:
                ContentFrame.Navigate(new LibraryPage(this, search));
                tabLabel = TracksTab;
                break;

            case Menu.Artists:
                ContentFrame.Navigate(new LibraryPage(this, search));
                tabLabel = ArtistsTab;
                break;

            case Menu.Albums:
                ContentFrame.Navigate(new LibraryPage(this, search));
                tabLabel = AlbumsTab;
                break;

            case Menu.Playlists:
                ContentFrame.Navigate(new LibraryPage(this, search));
                tabLabel = PlaylistsTab;
                break;

            case Menu.Import:
                ContentFrame.Navigate(new ImportPage(this));
                tabLabel = ImportTab;
                break;

            default:
                tabLabel = null;
                break;
            }
            ContentFrame.NavigationService.RemoveBackEntry();
            //TabChanged?.Invoke(null, search);
            TracksTab.FontWeight = ArtistsTab.FontWeight = AlbumsTab.FontWeight = PlaylistsTab.FontWeight = ImportTab.FontWeight = FontWeights.Normal;
            tabLabel.FontWeight  = FontWeights.Bold;
        }
        private void Player_SongChanged(object sender, EventArgs e)
        {
            if (!InFullscreen)
            {
                Mouse.OverrideCursor = null;
            }
            CurrentTrack        = Player.Metadata;
            Title               = $"{string.Join(", ", CurrentTrack.Artists)} - {CurrentTrack.Title} | {WindowName}";
            TitleLabel.Text     = CurrentTrack.Title;
            ArtistLabel.Text    = string.Join(", ", CurrentTrack.Artists) == "" ? Properties.Resources.MAINWINDOW_NOARTIST : string.Join(", ", CurrentTrack.Artists);
            ProgressBar.Maximum = Player.CurrentBackend.TotalTime.TotalSeconds;
            if (Player.CurrentBackend.TotalTime.TotalSeconds != 0)
            {
                ProgressIndicator2.Text = Player.CurrentBackend.TotalTime.ToString(@"mm\:ss");
            }
            else
            {
                ProgressIndicator2.Text = "∞";
            }
            SetIntegrations(PlaybackStatus.Playing);
            UpdatePlayButtonState();
            if (CurrentTrack.CoverArt is null)
            {
                CoverArtBox.Source = null;
                SetCoverArtVisibility(false);
            }
            else
            {
                CoverArtBox.Source = BitmapFrame.Create(new MemoryStream(CurrentTrack.CoverArt), BitmapCreateOptions.None, BitmapCacheOption.None);
                SetCoverArtVisibility(true);
            }
            ProgressTimer.Start();
            if (PauseAfterCurrentTrack && !Player.Paused)
            {
                PlayPauseMethod();
                PauseAfterCurrentTrack = false;
            }

            LoggingHandler.Log("Changing tracks!");
        }
예제 #17
0
        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();
            }
        }
예제 #18
0
 public void Close()
 {
     LoggingHandler.Log("Closing SMTC integration");
     // nothing needs to be done
 }
        public async void ShowAuxilliaryPane(Pane pane, int width = 235, bool openleft = false)
        {
            LoggingHandler.Log($"Showing pane --> {pane}");

            UserControl GetPageForPane(Pane panex)
            {
                switch (panex)
                {
                case Pane.Settings:
                    return(new SettingsPage(this));

                case Pane.QueueManagement:
                    return(new QueueManagement(this));

                case Pane.Search:
                    return(new SearchPage(this));

                case Pane.Notifications:
                    return(new NotificationPage(this));

                case Pane.TrackInfo:
                    return(new TrackInfoPage(this));

                case Pane.Lyrics:
                    return(new LyricsPage(this));

                default:
                    return(null);
                }
            }

            if (Keyboard.IsKeyDown(Key.LeftShift))
            {
                new Window
                {
                    Content               = GetPageForPane(pane),
                    Width                 = 600,
                    Height                = 500,
                    Topmost               = true,
                    ShowInTaskbar         = false,
                    Owner                 = this,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                }.Show();
                return;
            }

            if (CurrentPane == pane)
            {
                await HideAuxilliaryPane();

                return;
            }
            if (CurrentPane != Pane.None)
            {
                await HideAuxilliaryPane(true);
            }

            if (!openleft)
            {
                DockPanel.SetDock(RightFrame, Dock.Right);
            }
            else
            {
                DockPanel.SetDock(RightFrame, Dock.Left);
            }
            RightFrame.Visibility = Visibility.Visible;
            RightFrame.Width      = width;
            RightFrame.Content    = GetPageForPane(pane);

            var sb = InterfaceUtils.GetThicknessAnimation(
                openleft ? new Thickness(width * -1 /*negate*/, 0, 0, 0) : new Thickness(0, 0, width * -1 /*negate*/, 0),
                new Thickness(0),
                TimeSpan.FromMilliseconds(120),
                new PropertyPath(MarginProperty),
                new ExponentialEase {
                EasingMode = EasingMode.EaseOut, Exponent = 3
            });

            sb.Begin(RightFrame);

            CurrentPane = pane;
        }