nikib3ro
nikib3ro

Reputation: 20596

How to detect that sound has ended in the XNA MediaPlayer?

I know how to use MediaPlayer.Play(song); to start playing some song/effect.

But how to detect that song/effect ended playing?

Upvotes: 3

Views: 825

Answers (1)

user155407
user155407

Reputation:

You may want to try implementing these two events:

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.activesongchanged.aspx

and

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.mediastatechanged.aspx

An alternate way would be to keep a MediaState variable called "previousState" or whatever, and each Update(), check the previous state for Stopped or Paused, and run whatever code you want in that if. Of course, afterward, update the previous by doing:

previousState = MediaPlayer.State;

Upvotes: 3

Related Questions