Looping a stream

Hi Arman



I can’t get my music stream to loop:


   public static int loadSong(String file, int ID) {
      int sound = SoundSystem.createStream(file, false);
      SoundSystem.addSampleToNode(sound, music);
      SoundSystem.bindEventToSample(sound, ID);
      SoundSystem.setStreamLooping(ID, true);
      return sound;
   }



Am I approaching this in the wrong way?

Thanks
/Per

Hrm… I’ve refactored my program some, and now I can’t even get the stream to play once :frowning:



The method now looks like this:


   public static void loadSong(String file, int ID) {
      int sound = SoundSystem.createStream(MUSIC_DIR + file, true);
      SoundSystem.addSampleToNode(sound, SoundManager.music);
      SoundSystem.bindEventToSample(sound, ID);
      SoundSystem.setStreamLooping(ID, true);
   }



And if I change the first line to:


int sound = SoundSystem.create3DSample(MUSIC_DIR + file);


It plays just fine, though I can't loop it or anything...

Maybe this has to do with my modification of the SampleLoader I posted about in this thread.

Have you looked at TestSoundGraph? It has looping audio in that.

Ah, thanks for the tip. It seems that if you just add a sample to a node (not binding it to an event or anything) it gets looped automatically.



However, this is working for me atm:


   public static int loadSong(String file) {
//      int sound = SoundSystem.createStream(MUSIC_DIR + file, false);
      int sound = SoundSystem.createStream("C:/music.ogg", false);
      SoundSystem.addSampleToNode(sound, FoundationGame.music);
      SoundSystem.setStreamLooping(sound, true);
      return sound;
   }



Note the need to specify the absolute path :(

I started to refactor the system to take an URL instead, but it's just so many calls (one open method that calls another that calls another etc.) :?

Hope it'll get fixed soon

Also, Arman, it'd be great if streams could be binded to events the same way as samples can.

Well I will look at that as soon as I can,(my job is sucking my spare time for the moment :frowning: )



The way you create a music stream is not correct because the streams are not intended to bo part of a node (only samples are), they should be played directly





int sound = SoundSystem.createStream(MUSIC_DIR + file, false);
SoundSystem.setStreamLooping(sound, true);
SoundSystem.playStream(sound);


is sufficent to create a stream

In order to create a short sample (effect)
you
do like



int sound=SoundSystem.create3DSample(yourfile);
    SoundSystem.setSampleMaxAudibleDistance(sound, 100);
SoundSystem.bindEventToSample(sound, ID);
SoundSystem.addSampleToNode(sound, SoundManager.music);




Hope that this helps

Yup - that’s what I’ve got working now. What needs to get fixed is the need to specify an absolute path.