#Audio Playback

1 messages · Page 1 of 1 (latest)

whole halo
#

Does anyone know how to get sound effects to overlap themselves? I'm making an audio system right now and I can't for the life of me figure out how to allow a sound effect to play over itself, here's the basic idea: ```java
public class SoundEffect {
private InputStream inputStream;
private AudioInputStream audioStream;
private Clip audioClip;
private DataLine.Info info;
private long clipTime;
private boolean overlapClip;

public SoundEffect(String pathToResource) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
    inputStream = getClass().getClassLoader().getResourceAsStream(pathToResource);
    audioStream = AudioSystem.getAudioInputStream(inputStream);
    AudioFormat format = audioStream.getFormat();
    info = new DataLine.Info(Clip.class, format);
    audioClip = (Clip) AudioSystem.getLine(info);
    audioClip.addLineListener(new SoundClipListener());
    audioClip.open(audioStream);
}

public void start() {
    if(overlapClip) {
        // What can I do to play both clips at once here instead of restarting the currently playing clip?
    } else if(!audioClip.isRunning()) {
        audioClip.setMicrosecondPosition(0);
        audioClip.start();
    }

}

}

Also if anyone has a better idea of handling sounds, let me know!
spiral crestBOT
#

This post has been reserved for your question.

Hey @whole halo! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

sturdy basin
#

i tried to do an audio system a while ago (didnt go well) but iirc you need to have two clips which you start simultaniously

potent jolt
#

possibly on two distinct lines

#

or you could maybe try to create a new clip consisting of the "addition" of both clips