SunsetHigh.BGMusic.playSong C# (CSharp) Method

playSong() public static method

Begins playing a song with the specified file name. Only .mp3, .wma, and .m4a are supported.
public static playSong ( string fileName ) : void
fileName string File name of the song in the "Content" directory
return void
        public static void playSong(string fileName)
        {
            if (fileName.StartsWith(Directories.MUSIC))
                fileName = fileName.Substring(Directories.MUSIC.Length);

            System.Diagnostics.Debug.WriteLine(fileName);
            if (fileName.Equals(currentSongName))
            {
                if (fadingOut)
                {
                   fadeIn();
                   System.Diagnostics.Debug.WriteLine("FADE in");
                }
                return;
            }
            if (playing)
                stopSong(); //cut off current song

            if (!tryAllFileTypes(fileName))
            {
                throw new System.IO.FileNotFoundException("Could not find the music file \"" + fileName + "\" in the \"Music\" directory"
                    + " in Content.\nMake sure the file is .mp3, .m4a, or .wma, and \"Copy to output directory\" settings"
                    + " are set to \"Copy if newer\".");
            }

            if (wavePlayer == null)
                wavePlayer = new WaveOutEvent(); //initialize wavePlayer

            fadeInOut = new FadeInOutSampleProviderAdapted(file);
            sampleToWave = new SampleToWaveProvider(fadeInOut);
            wavePlayer.Init(sampleToWave);

            if (!paused)
            {
                wavePlayer.Play();
                playing = true;
            }
            currentSongName = fileName;
        }