public void Constructor_NoParameters() { SongException songEx = new SongException(); Assert.Equal($"Exception of type '{typeof(SongException).FullName}' was thrown.", songEx.Message); Assert.Null(songEx.InnerException); }
public void Constructor_MessageProvided() { SongException songEx = new SongException("Test"); Assert.Equal("Test", songEx.Message); Assert.Null(songEx.InnerException); }
public void Constructor_MessageAndInnerExceptionProvided() { Exception innerEx = new InvalidOperationException(); SongException songEx = new SongException("Test", innerEx); Assert.Equal("Test", songEx.Message); Assert.Same(innerEx, songEx.InnerException); }
/// <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); } }