Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends I'm using this code to play sounds in mp3 and wav format in xna, I don't know how i can find out if the sound is completely played or not?
//Putting a sound in buffer for playing
fncPutAWavSoundOnBuffer(1);
fncPutAWavSoundOnBuffer(2);



XML
public bool songbuffer = false;
       public bool soundbuffer = false;
       public Song CurrentSong;
       public SoundEffect CurrentSound;
       public void fncPutAMP3SoundOnBuffer(int code)
       {
           CurrentSong = content.Load<Song>(GivemeSoundFileNameByCode(code));
           songbuffer = true;
       }
       public void fncPutAWavSoundOnBuffer(int code)
       {
           CurrentSound = content.Load<SoundEffect>(GivemeSoundFileNameByCode(code));
           soundbuffer = true;
       }





C#
public string GivemeSoundFileNameByCode(int code)
        {
            string BaseDirectory = ".";
            switch (code)
            {
                case 1:
                    {
                        return BaseDirectory + "\\StartPage\\Sounds\\ButtonMouseOverSound";
                    }
                case 2:
                    {
                        return BaseDirectory + "\\StartPage\\Sounds\\ButtonClickSound";
                    }
                case 3:
                    {
                        return BaseDirectory + "\\AddNewWordsPage1\\Sounds\\mp3PleaseWiteYourWordHere";
                    }
                default:
                    {
                        break;
                    }
            }
            return "";
        }



C#
protected override void Update(GameTime gameTime)
     {
         // Allows the game to exit
         if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
             this.Exit();
         PlaySound();
         base.Update(gameTime);
     }


C#
public void PlaySound()
      {
          if (clsMyDefenition.soundbuffer)
          {
              clsMyDefenition.CurrentSound.Play();
              clsMyDefenition.soundbuffer = false;
          }
          if (clsMyDefenition.songbuffer)
          {
              MediaPlayer.Play(clsMyDefenition.CurrentSong);
              clsMyDefenition.songbuffer = false;
          }
      }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900