Esempio n. 1
0
        private void songExceptionHandler(object sender, PlaybackExceptionEventArgs e)
        {
            Notification notification = new Notification("An error occured.", $"{e.Details}\nWe'll skip to the next track for you.", 2500);

            notification.Location = Location;
            notification.Show();
            Player.NextSong();
        }
 void Player_Exception(object s, PlaybackExceptionEventArgs e)
 {
     using var md = new MessageDialog(this,
                                      DialogFlags.Modal,
                                      MessageType.Error,
                                      ButtonsType.Ok,
                                      null);
     md.Text = e.Details;
     md.Run();
 }
 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 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();
 }
Esempio n. 5
0
        /// <summary>
        /// Starts playing the Queue. In order to play a track, you must first add it to the Queue using <see cref="AddQueue(string)"/>.
        /// </summary>
        /// <param name="repeat">If true, avoids dequeuing the next track. Not to be used for anything other than the player.</param>
        public void PlayMusic(bool repeat = false)
        {
            if (!repeat && Queue.Count != 0)
            {
                FilePath = Queue[QueuePosition];
            }
            QueuePosition++;

            void PMusic()
            {
                //TODO: Check if FilePath is a file
                //maybe we can use cd://2 for CD track 2, and anything else we can use the NAudio backend?

                if (true)
                {
                    currentBackend = new NAudioBackend(FilePath);
                }

                currentBackend.Play();
                currentBackend.Volume             = CurrentVolume;
                currentBackend.OnPlaybackStopped += OnPlaybackStopped;

                Playing = true;
            }

            try
            {
                if (Playing != true)
                {
                    PMusic();
                }
                else
                {
                    AvoidNextQueue = true;
                    StopMusic();
                    PMusic();
                }

                SongChanged?.Invoke(null,
                                    EventArgs.Empty); // Now that playback has started without any issues, fire the song changed event.
            }
            catch (System.IO.FileNotFoundException)
            {
                var args = new PlaybackExceptionEventArgs {
                    Details = "That's not a valid file path!"
                };
                SongException?.Invoke(null, args);
            }
            catch (ArgumentException)
            {
                var args = new PlaybackExceptionEventArgs {
                    Details = "That's not a valid file path!"
                };
                SongException?.Invoke(null, args);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                var args = new PlaybackExceptionEventArgs {
                    Details = "This isn't a valid audio file!"
                };
                SongException?.Invoke(null, args);
            }
            catch (FormatException)
            {
                var args = new PlaybackExceptionEventArgs {
                    Details = "This audio file might be corrupt!"
                };
                SongException?.Invoke(null, args);
            }
            catch (InvalidOperationException)
            {
                var args = new PlaybackExceptionEventArgs {
                    Details = "This audio file uses VBR \nor might be corrupt!"
                };
                SongException?.Invoke(null, args);
            }
            catch (Exception e)
            {
                var args = new PlaybackExceptionEventArgs {
                    Details = $"{e.Message}\n{e.StackTrace}"
                };
                SongException?.Invoke(null, args);
            }
        }
Esempio n. 6
0
 private void Player_songException(object sender, PlaybackExceptionEventArgs e)
 {
     MessageBox.Show("something did a fucky wucky");
 }
 private void Player_songException(object sender, PlaybackExceptionEventArgs e)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Starts playing the queue. In order to play a track, you must first add it to the queue using <see cref="AddQueue(string)"/>.
        /// </summary>
        /// <param name="repeat">If true, avoids dequeuing the next track. Not to be used for anything other than the player.</param>
        public static void PlayMusic(bool repeat = false)
        {
            if (!repeat && Queue.Count != 0)
            {
                filePath = Queue[QueuePosition];                              // Some functions want to play the same song again
            }
            QueuePosition++;
            void PMusic()
            {
                if (outputDevice == null)
                {
                    outputDevice = new WaveOutEvent();
                    outputDevice.PlaybackStopped += OnPlaybackStopped;
                }
                if (audioFile == null)
                {
                    audioFile = new AudioFileReader(filePath);
                    outputDevice.Init(audioFile);
                }
                outputDevice.Play();
                outputDevice.Volume = currentvolume;
                playing             = true;
            }

            try
            {
                if (playing != true)
                {
                    PMusic();
                }
                else
                {
                    avoidnextqueue = true;
                    StopMusic();
                    PMusic();
                }
                songChanged?.Invoke(null, EventArgs.Empty); // Now that playback has started without any issues, fire the song changed event.
            }
            catch (System.IO.FileNotFoundException)
            {
                PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs();
                args.Details = "That's not a valid file path!";
                songException.Invoke(null, args);
            }
            catch (System.ArgumentException)
            {
                PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs();
                args.Details = "That's not a valid file path!";
                songException.Invoke(null, args);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs();
                args.Details = "This isn't a valid audio file!";
                songException.Invoke(null, args);
            }
            catch (System.FormatException)
            {
                PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs();
                args.Details = "This audio file might be corrupt!";
                songException.Invoke(null, args);
            }
            catch (System.InvalidOperationException)
            {
                PlaybackExceptionEventArgs args = new PlaybackExceptionEventArgs();
                args.Details = "This audio file uses VBR \nor might be corrupt!";
                songException.Invoke(null, args);
            }
        }