Hey
Can somebody please help me, i’ve got some code so that it plays a background sound, its working but i cannot get it to loop, it must be something simple, but any help will be appreciated.
thanks in advance
CODE:
protected void addBackgroundSound (BranchGroup b,String soundFile) {
//Create a media container to load the file
MediaContainer droneContainer = new MediaContainer(soundFile);
//Create the background sound from the media container
BackgroundSound drone = new BackgroundSound(droneContainer,1.0f);
//Activate the sound
drone.setSchedulingBounds(bounds);
drone.setEnable(true);
//Set the sound to loop forever
drone.setLoop(BackgroundSound.INFINITE_LOOPS);
//Add it to the group
b.addChild(drone);
}
protected void addObjectSound(TransformGroup tg, PointSound sound,
String soundFile, float edge) {
//First we get the current transform so that we can
//position the sound in the same place
Transform3D objXfm = new Transform3D();
Vector3f objPosition = new Vector3f();
tg.getTransform(objXfm);
objXfm.get(objPosition);
//Create the media container to load the sound
MediaContainer soundContainer = new MediaContainer(soundFile);
//Use the loaded data in the sound
sound.setSoundData(soundContainer);
sound.setInitialGain(1.0f);
//Set the position to that of the given transform
sound.setPosition(new Point3f(objPosition));
//Allow use to switch the sound on and off
sound.setCapability(PointSound.ALLOW_ENABLE_READ);
sound.setCapability(PointSound.ALLOW_ENABLE_WRITE);
sound.setCapability(PointSound.ALLOW_LOOP_WRITE);
sound.setSchedulingBounds(bounds);
//Set it off to start with
sound.setEnable(false);
//Set it to loop forever
sound.setLoop(BackgroundSound.INFINITE_LOOPS);
//Use the edge value to set to extent of the sound
Point2f[] attenuation = {new Point2f(0.0f,1.0f),
new Point2f(edge,0.1f)};
sound.setDistanceGain(attenuation);
//Add the sound to the transform group
tg.addChild(sound);
}