In "real" XNA is it safe to do so in any of the methods you listed, although I would recommend BeginRun
myself, which is called once, immediately before the first call to Update
.
protected override void BeginRun()
{
MediaPlayer.Play(song);
base.BeginRun();
}
MonoGame has historically implemented the startup sequence with subtle differences to the real XNA. But in this case it's probably quite safe to treat it like XNA. (I think at one stage it didn't even have the BeginRun
method in Game
- hopefully that's been fixed.)
It's totally reasonable and safe to simply do this:
bool songStarted = false;
protected override void Update(GameTime gameTime)
{
if(!songStarted)
{
MediaPlayer.Play(song);
songStarted = true;
}
// ...
}
Which may seem over-done in this context, but starts to make more sense when you need to have greater control over music playback (eg: starting a song at the beginning of each level).
Finally, you may be tempted to implement the above check by checking the MediaPlayer.State
property each frame (instead of your own boolean). I strongly recommend not doing this, as (at least in XNA) this is a slow, blocking operation that can significantly slow down your game.