Problems with JME Audio

I am working on a project with a couple of friends for school. We use the JME AudioSystem, AudioTrack, MusicTrackQueue, and MusicTrackQueue.RepeatType classes to create audio playback for background music in our game. I have three questions about these classes.

  1. How can we sync the beginning of playback with the beginning of the battle?
  2. We are having a problem where we can’t stop music playback after a battle ends. This is really bad, because if another stage is selected, you have two audio tracks playing simultaneously, which introduces lag. We are also attempting to lower the volume of the audio when the game is paused. This also does not work. How do we fix these problems?
  3. Similar to the music tracks in many video games, for each song for a stage, we have an intro part and the main part which is repeated. The way we currently implement this is by having two separate music files and adding them both to the queue. Then when the second track starts playing, the first intro track is removed from the queue and it is set to repeat. For some strange reason, the second track always starts louder than the last. Is there a fix for this?

    Here is the code:

    [java]public class BgmPlayer {

    private static String baseURL = “com/googlecode/reaxion/resources/audio/tracks/”;

    private static String filename;

    private static String ext;

    private static MusicTrackQueue queue;

    private static AudioTrack intro;

    private static AudioTrack track;

    private static boolean hasBGM = false;

  • Prepares the queue to load sounds.


    public static void prepare() {

    queue = AudioSystem.getSystem().getMusicQueue();




    queue.addCurrentSongChangeListener(new SongChangeListener());


  • Plays and loops a background music track. If a file with “-intro” exists,
  • it will be loaded first and play on the first playback.

  • @param f
  •        Filename of track and track-intro file<br />


public static void play(String f) {

hasBGM = true;


filename = f.substring(0, f.length() - 4);

ext = f.substring(f.length() - 4);

intro = AudioSystem.getSystem().createAudioTrack(


baseURL + filename + “-intro” + ext), false);

track = AudioSystem.getSystem().createAudioTrack(


baseURL + filename + ext), false);





  • Clears all tracks from the queue and frees them from memory.


    public static void stopAndReset() {

    if (hasBGM) {


    ArrayList tracks = queue.getTrackList();

    for (int i = 0; i < tracks.size(); i++) {





    hasBGM = false;



    public static void gamePaused() {

    if (hasBGM)



    public static void gameUnpaused() {

    if (hasBGM)



    private static class SongChangeListener implements ChangeListener {

    public void stateChanged(ChangeEvent e) {





Note: The import statements are missing at the top because i didn’t copy them. lol.