Example #1
0
 /// <summary>
 /// Disposes of all resources contained in BGMusic. Call this method at the 
 /// end of the Game's life.
 /// </summary>
 public static void dispose()
 {
     if (file != null)
     {
         file.Dispose();
         file = null;
     }
     if (wavePlayer != null)
     {
         wavePlayer.Dispose();
         wavePlayer = null;
     }
     fadeInOut = null;
 }
Example #2
0
        /// <summary>
        /// Begins playing a song with the specified file name. Only .mp3, .wma, and .m4a are supported.
        /// </summary>
        /// <param name="fileName">File name of the song in the "Content" directory</param>
        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;
        }