Example #1
0
        } // Pauses the music without completely disposing it

        /// <summary>
        /// Resumes playback.
        /// </summary>
        public void ResumeMusic()
        {
            if (Paused)
            {
                currentBackend?.Play();
            }
            //playing = true;
            Paused = false;
        } // Resumes music that has been paused
Example #2
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);
            }
        }