BGM synchronize

Is there a way to put a flag in the background music and keep it in sync?
We would like to influence the game to match the rhythm of the music.

in Japanese.

I’m not sure I understand this question. Assuming you mean you want some event to happen at X timestamp of the music, just set a timer to run that event X time after you run the play function for the music. Or do you mean something else?

1 Like

This might have the answer you are looking for or the code to find the next question…


Creating a steady rhythm for music-based game in XNA - Game Development Stack Exchange


You could define your own flags and run that alongside the music.


1 Like

Thanks for the reply!
I have been thinking about that too.
But I don’t think they are in perfect sync.
If the music is delayed in any way, it can cause misalignment.

Thanks for the reply!
I guess I still have to manage by the time.
public static MediaPlayer.TimeSpan PlayPosition { get; }
I found it and will try this!


If that doesn’t solve your issue, you can use the SoundEffect/SoundEffectInstance classes to play music. I’ve found it to be much less finicky and has features the Song class lacks. I believe this originally came about for me because one of our prototypes had 2 tracks that it needed to swap between at the same timestamp, so they’d be in sync but switch to the other track under certain conditions. I needed to use SoundEffectInstance to make that happen, if memory serves.

1 Like

Thanks for the reply!
I use MediaPlayer for BGM、I use SoundEffect(~Instance) for SE.
Certainly for BGM, I have never tried SoundEffect(~Instance),I will experiment!
I can also get the TimeSpan.