Exemplo n.º 1
0
        public MainWindow()
        {
            this.StartServer();

            Trace.TraceInformation("[Player startup] Preparing main window to display...");

            InitializeComponent();
            Menu.Opacity = 0;

            this.viewModel = new MainWindowViewModel(this)
            {
                Playlist = this.Playlist
            };
            this.DataContext = viewModel;

            this.PreparePlaybackController();
            this.Icon = TomiSoft.MP3Player.Properties.Resources.AbstractAlbumArt.ToImageSource();

            //Attaching a null-playback instance to display default informations.
            Trace.TraceInformation("[Player startup] Attaching a NULL-playback manager");
            this.AttachPlayer(
                PlaybackFactory.NullPlayback(100)
                );

            //Load BASS with its all plugins.
            Trace.TraceInformation("[Player startup] Initializing BASS library...");
            if (!BassManager.Load())
            {
                Trace.TraceError("[Player startup] Fatal error occured. Terminating application...");
                PlayerUtils.ErrorMessageBox(App.Name, "Nem sikerült betölteni a BASS-t.");
                Environment.Exit(1);
            }

            //Initialize BASS output device.
            Trace.TraceInformation("[Player startup] Initializing audio output device");
            if (!BassManager.InitializeOutputDevice())
            {
                Trace.TraceError("[Player startup] Fatal error occured. Terminating application...");
                PlayerUtils.ErrorMessageBox(App.Name, "Nem sikerült beállítani a hangkimenetet.");
                Environment.Exit(1);
            }

            this.Loaded += RegisterHotKeys;
            this.Playlist.SelectedSongChanged += Playlist_SelectedSongChanged;
            this.Closed += WindowClosed;
            PlaybackFactory.MediaOpenProgressChanged += (Percentage, StatusString) => {
                this.viewModel.Lyrics = StatusString;
            };

            Trace.TraceInformation("[Player startup] Startup successful.");

            this.ProcessCommandLine();
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is executed when the selected song in playlist is
        /// changed.
        /// </summary>
        /// <param name="sender">The Playlist instance</param>
        /// <param name="e">Event parameters</param>
        private async void Playlist_SelectedSongChanged(object sender, EventArgs e)
        {
            this.Player?.Stop();

            #region Error checking
            //If the playlist is empty, we need to attach a NULL-playback
            //manager and prevent any other actions.
            if (this.Playlist.CurrentSongInfo == null)
            {
                this.AttachPlayer(PlaybackFactory.NullPlayback(this.Player.Volume));
                return;
            }
            #endregion

            IPlaybackManager NewPlaybackManager = null;
            try {
                this.viewModel.LyricsReader = null;
                this.viewModel.Lyrics       = "Zene megnyitása...";

                NewPlaybackManager = await PlaybackFactory.LoadMedia(this.Playlist.CurrentSongInfo);
            }
            catch (Exception ex) {
                if (ex is IOException || ex is NotSupportedException)
                {
                    new Toast(App.Name)
                    {
                        Title   = "Hoppá...",
                        Content = "Ezt a fájlt nem tudjuk megnyitni.",
                        Image   = TomiSoft.MP3Player.Properties.Resources.AbstractAlbumArt
                    }.Show();
                }

                return;
            }

            this.AttachPlayer(NewPlaybackManager);

            this.Player?.Play();

            //Load lyrics
            this.OpenLyricsAsync(this.Playlist.CurrentSongInfo);
        }