Hey guys i’m new on this forum, so i’m sorry if this is the wrong place to post this. My question is, how can i loop a MP3? Actually i’m using JLayer and i can loop it twice, only twice, and after the music stops but not the game. What happens to me?
MP3 includes a short amount of silence at the start – use OGG or WAV for loops.
But the music stops complety. will the music stop complety if I use ogg? Because I don’t want to use WAV files they are too heavy.
The music will still stop if u use an ogg, I know there is a way to progam this, but sorry Im also a newb lol idk how:(
I’m not really sure about the library that you are using, but most likely you can do this in two ways:
- Calculate milliseconds of audio and call the play method of the song when a timer reaches that millisecond value.
- If your library has a boolean for all songs called finished, you can just check if finished == true in your game loop and if it is true then call the play method of the song.
The 2nd option is more efficient.
Let me know if either of these don’t make sense, I can elaborate on them if necessary.
If you are using JLayer, they have a Listener in the API. If you override that, you should be able to tell when the music stops and start it all over from the beginning.
Or you can just check out TinySound if you want functionality like this for ogg, mp3’s, and the like. It works pretty well if you are just trying to get music working.
I recommend TinySound! I used it in my first game and it worked really well.
Okay TinySound is pretty good for me
and here the big question. a post ago i said WAV was very heavy… So now my question is: Really? Is it too heavy for a background music loop? ???
Odd question! Don’t confuse the way you distribute sounds with the way you play them. You can ship them compressed, and uncompress them into memory at runtime (as long as they’re not too big) which will give you better seamless looping, or stream them and uncompress on the fly. It looks like TinySound uses the standard JavaSound stream support, which means it can either stream or load WAVs by default. However, if you put JARs on the classpath that are JavaSound service providers, it should be able to load other formats. There is OGG support in the TinySound repo, and it should be able to load MP3 in the same way by putting the right JLayer JAR on your classpath.
Well just in terms of space WAV is huge and OGG is really low, so I suggest OGG since it’ll make your game download faster. Thus, your players will have more time to play.