Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a game with XNA and trying to get some background music to loop correctly. Because the file is an MP3 of about 30 seconds in length, I instantiated it as a Song. I want it to loop perfectly, but even when I set the MediaPlayer.IsRepeating property to true, there is always a delay of about one second before the song starts up again. Is there any way to eliminate this delay such that the song loops instantly, so it can play more fluently?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

The MediaPlayer in XNA has always had a short delay when looping songs and I haven't seen any way to resolve the issue. What is your target platform? You could consider using XACT if you are targeting the Xbox or Windows as it doesn't have the same issues as the MediaPlayer API.

I'd recommend against using SoundEffect (as recommended by Sprunth) to play background music if you are going to release on XBLIG or the WP7 marketplace as that doesn't mesh well with the built in media player and leads to certification/peer review issues. For example, if you play your background music as a SoundEffect on the Xbox and a player wants to use their own custom soundtrack your music will still keep playing over top, whereas if you had used a Song as recommended it would "magically" stop. Similar bad things happen on the phone.

share|improve this answer
3  
Thanks for clarifying why Song is the proper choice here. –  Stephane Beniak Nov 28 '11 at 16:34
    
+1 For XACT. You should be importing your music and sound effects as uncompressed WAV files and allowing XACT to compress them and pack them into wavebanks. –  michael.bartnett Nov 29 '11 at 1:40

I made a quick xna app with a ~15 second mp3 and can confirm that MediaPlayer does have this issue when looping. I tried it again with SoundEffect (and SoundEffectInstance for looping in XNA4) and the issue disappeared. So I guess you could switch to SoundEffect?

Some research/sources: Looping music using MediaPlayer problem Ways of fixing the delay gap when looping MP3s in XNA 3.0

share|improve this answer
    
+1 using soundeffect works perfectly –  Oskar Duveborn Nov 28 '11 at 13:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.