Play ONCE!? SimpleGame good, but StandardGame bad?

Sirs, I have the following code:



      AudioTrack track = AudioSystem.getSystem().createAudioTrack(ScreenMedia.class.getResource("menem1.wav"), false);
      track.setType(TrackType.MUSIC);
      track.setRelative(true);
      track.setTargetVolume(0.7f);
      track.setLooping(false);
      MusicTrackQueue queue = AudioSystem.getSystem().getMusicQueue();
      queue.setCrossfadeinTime(0);
      queue.setRepeatType(RepeatType.ONE);
      queue.addTrack(track);
      queue.play();



When I run it in SimpleGame it works fine, it only plays once, I mean, it just repeats 1 time, as setted. But when I run it using StandardGame it doesn't work fine, it REPEATS TO THE INFINITE! Non-stop loop when running in StandardGame... why?

well, actually where in StandardGame are you playing the sound ?



edit:

nm :slight_smile: i just tested it myself and strangely it repeats really

StandardGame handles audio itself, if you actually check the code.  The StandardGame that I use is simply the same thing, except with the audio removed.  Darkfrog (how do we summon the frog?) would be the one to answer as to whether this is simply an oversight, but I believe that you should deal with audio yourself in a separate GameState.



I don't know if this suits your purpose, but I remember it was pretty easy for me to do and works well.

If you guys believe sound should be removed from StandardGame I wouldn't be opposed to that.  However, I would recommend posting a poll to get some feedback as to whether it should be removed as lots of people are using it and I'd hate to remove it if it's going to cause havoc for a lot of people.

:expressionless: Mmmm… I have to solve this issue asap as on monday I have my first pre-production release.


StandardGame handles audio itself, if you actually check the code.  The StandardGame that I use is simply the same thing, except with the audio removed.



So you mean you have your custom-StandardGame (StandardGame-modified) in which you removed all sound treatment. Right? But, is it a solution to this, I mean, does it make the sounds to repeat-only once as setted in the code shown before?

I need a solution...  :'(

You mixed music and audiotrack up somehow i think:

there is no need for the Music queue if you want to play a single Sound Fx.


public class StandardSound {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        StandardGame game = new StandardGame("sound");
        game.getSettings().setSFX(true);
        game.getSettings().setMusic(true);
        game.start();
       
        AudioTrack track = AudioSystem.getSystem().createAudioTrack(SimpleSound.class.getResource("shoot.wav"), false);
        track.setType(TrackType.MUSIC);
        track.setRelative(true);
        track.setTargetVolume(0.7f);
        track.setLooping(false);
        track.play();
    }
}



edit:
hmm well on the other hand i am not sure how to do it 'correctly' and its strange that it behaves different in simple / standardgame.
but i don't see a reason to add a track which you want to play once to a music queue.

Thanks a lot Core-Dump! I can do it without MusicTrackQueue. Removing it did well  :wink:



Anyway, the problem with MusicTrackQueue and StandardGame seem to persist yet. The sample JME code TestMusicQueue has the same RepeatType.ONE and the Footsteps.wav repeats infinitely.  :expressionless:

RepeatType.ONE means repeat the current song over and over.  :slight_smile:

doh ok there is also RepeatType.NONE , could you add this infos to the java doc of MusicTrackQueue?  :slight_smile:

RepeatType.ONE means repeat the current song over and over.


Very "intuitive"...  :D

Anyway, it doesn't work the same in SimpleGame and StandardGame.

doh ok there is also RepeatType.NONE


Mmm... and also RepeatType.ALL... really, non-intuitive-sense... no doubt, java-doc is wellcome there, or some kind of refactor I guess.  :|

Actually, this is pretty common in most media players.  You click repeat and it will repeat all the songs in the play list, you click it again and it narrows that to just the currently playing song, you click it again and it turns off repeat mode.  But, sure, javadoc would help make that more clear.

Actually, this is pretty common in most media players.  You click repeat and it will repeat all the songs in the play list, you click it again and it narrows that to just the currently playing song, you click it again and it turns off repeat mode.  But, sure, javadoc would help make that more clear.


Renanse, this explanation make it perfectly clear. The idea is understandable and clear now, and it's a nice idea. I guess this same comments in java-doc are enough to guide well. 

Thanks  ;)

Sure thing. :slight_smile: