public static void loopClip(Clip clip, int n) { if (clip != null) { clip.stop(); clip.setFramePosition(0); clip.loop(n); } }
public void playAudio() { if (audio != null) { audio.stop(); audio.setFramePosition(0); audio.start(); if (loops.get(0) == true) { audio.loop(Clip.LOOP_CONTINUOUSLY); } } }
/*Routine to play theme*/ public void playTheme() { File sound = new File("Death on the Dance Floor_1.wav"); try { Clip clip = AudioSystem.getClip(); clip.open(AudioSystem.getAudioInputStream(sound)); // open the specified clip clip.start(); // start it clip.loop(Clip.LOOP_CONTINUOUSLY); // loop it } catch (Exception e) { System.out.println(e); } }
private static void playWav(String name, boolean loop, double volume) throws FileNotFoundException, IOException, UnsupportedAudioFileException, LineUnavailableException { AudioInputStream ais = AudioSystem.getAudioInputStream(new File(path + name)); Clip clip = AudioSystem.getClip(); clip.open(ais); if (loop) { clip.loop(-1); } ((FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN)) .setValue((float) (Math.log(volume) / Math.log(10.) * 20.)); clip.start(); wavMap.put(name, clip); // // open the sound file as a Java input stream // InputStream in = new FileInputStream(path + name); // // create an audiostream from the inputstream // AudioStream audioStream = new AudioStream(in); // // play the audio clip with the audioplayer class // AudioPlayer.player.start(audioStream); // wavMap.put(name, audioStream); }