Click here to Skip to main content
12,622,741 members (28,132 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: XNA4.0
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);



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;
       }




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 "";
        }


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);
     }

public void PlaySound()
      {
          if (clsMyDefenition.soundbuffer)
          {
              clsMyDefenition.CurrentSound.Play();
              clsMyDefenition.soundbuffer = false;
          }
          if (clsMyDefenition.songbuffer)
          {
              MediaPlayer.Play(clsMyDefenition.CurrentSong);
              clsMyDefenition.songbuffer = false;
          }
      }
Posted 21-Jan-13 11:35am

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100