0

I'm a bit stumped here. I need background music for the game I'm making, and for most songs, there will be a beginning section that will head into a loop once it's done playing (aka an intro). Although this seems kinda simple, I haven't been able to find anything that would do this. Could anyone help? Thanks!

EDIT: Screwed up a tag

TheGag96
  • 11
  • 2

2 Answers2

1

First of all, I recommend you to use OGG instead of MP3, has better performance.

You have to separate the music into two tracks, one with the intro, and one with the looping part. In the code you have to initialize both tracks as two different Music objects. Set the looping in the object with the intro track to false and start playing it. Now on each cycle of the game you have to check if the intro track is playing, if not, start playing the loop (You have to make additional checkings if you can stop the music by other means, e.g: pausing the game).

Depending of the performance of the computer, the change will be amost unnoticeable or be a small gap.

B.K.
  • 211
  • 1
  • 6
0

edit:

my bad, I saw Java and automatically assumed it was Android.

Try looking in this answer

Community
  • 1
  • 1
thepoosh
  • 12,497
  • 15
  • 73
  • 132
  • But that's in the Android SDK, and I definitely don't want to be dependent on it. Also, this loops the song, but doesn't allow you to set at what points it loops. – TheGag96 Apr 29 '12 at 08:03
  • sorry, honest mistake. edited the answer for your specific needs – thepoosh Apr 29 '12 at 08:06