/** * Loops an audio file (in .wav, .mid, or .au format) in a background thread. * * @param filename the name of the audio file * @throws IllegalArgumentException if {@code filename} is {@code null} */ public static synchronized void loop(String filename) { if (filename == null) throw new IllegalArgumentException(); // code adapted from: http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java try { Clip clip = AudioSystem.getClip(); InputStream is = StdAudio.class.getResourceAsStream(filename); AudioInputStream ais = AudioSystem.getAudioInputStream(is); clip.open(ais); clip.loop(Clip.LOOP_CONTINUOUSLY); } catch (UnsupportedAudioFileException e) { throw new IllegalArgumentException("unsupported audio format: '" + filename + "'", e); } catch (LineUnavailableException e) { throw new IllegalArgumentException("could not play '" + filename + "'", e); } catch (IOException e) { throw new IllegalArgumentException("could not play '" + filename + "'", e); } }
e.printStackTrace(); m_clip.loop(loop); if (waitUntilCompleted) m_clip.drain();
e.printStackTrace(); m_clip.loop(loop); if (waitUntilCompleted) m_clip.drain();
import java.io.File; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; public class Snippet { public static void main(String[] args) throws Exception { AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("notify.wav")); Clip clip = AudioSystem.getClip(); clip.open(inputStream); clip.loop(Clip.LOOP_CONTINUOUSLY); Thread.sleep(10000); // looping as long as this thread is alive } }
clip.loop(Clip.LOOP_CONTINUOUSLY);
private SoundChain play(final Sound sound, boolean repeatedly, final SoundChain chain) { stop(sound); if(sound.disabled()) { chain.takeOver(); return chain; } try { InputStream stream = sound.inputStream(); //wrap the stream in another one that supports mark/reset (see issue #31) stream = new BufferedInputStream(stream); AudioInputStream input = AudioSystem.getAudioInputStream(stream); Clip clip = AudioSystem.getClip(); clip.addLineListener(new ClipHandler(sound, chain)); clip.open(input); if(repeatedly) { clip.loop(Clip.LOOP_CONTINUOUSLY); } else { clip.start(); } activeClips.put(sound, clip); } catch (Exception e) { logger.error("Error while playing sound: " + sound, e); } return chain; }
/** * Plays the clip in a continuous loop until the stop method is * called. */ public void loop() { if (clip == null) return; clip.loop(Clip.LOOP_CONTINUOUSLY); }
public void play(File file) throws LineUnavailableException{ Clip clip=AudioSystem.getClip(); clip.open(AudioSystem.getAudioInputStream(file)); clip.loop(1); }
public void sound() { try{ AudioInputStream ais = AudioSystem.getAudioInputStream(new File("./sounds/player-laser.wav")); Clip test = AudioSystem.getClip(); test.open(ais); test.loop(0); }catch(Exception ex){ ex.printStackTrace(); } }
private void playClip(Clip clip, long duration) { clip.loop(Clip.LOOP_CONTINUOUSLY); try { Thread.sleep(duration); } catch (InterruptedException e) { // Ignore Exception } clip.stop(); }
InputStream input = getClass().getResourceAsStream("/Sound/plague.wav"); AudioInputStream audioIn = AudioSystem.getAudioInputStream(input); Clip clip = AudioSystem.getClip(); clip.open(audioIn); clip.loop(Clip.LOOP_CONTINUOUSLY); } catch (LineUnavailableException ex) { Logger.getLogger(knownDiseases.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(knownDiseases.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedAudioFileException ex) { Logger.getLogger(knownDiseases.class.getName()).log(Level.SEVERE, null, ex); }
if(true) { File file = new File("GodzillaWAV.wav"); Clip clip = AudioSystem.getClip(); AudioInputStream Audio = AudioSystem.getAudioInputStream(file); clip.open(Audio); clip.loop(Clip.LOOP_CONTINUOUSLY); Thread.sleep(6000); }
@Override protected boolean playImpl() { impl.setFramePosition(0); if (looping) { impl.loop(Clip.LOOP_CONTINUOUSLY); } else { impl.start(); } return true; }
@Override protected boolean playImpl() { impl.setFramePosition(0); if (looping) { impl.loop(Clip.LOOP_CONTINUOUSLY); } else { impl.start(); } return true; }
@Override protected boolean playImpl() { impl.setFramePosition(0); if (looping) { impl.loop(Clip.LOOP_CONTINUOUSLY); } else { impl.start(); } return true; }
@Override protected boolean playImpl() { impl.setFramePosition(0); if (looping) { impl.loop(Clip.LOOP_CONTINUOUSLY); } else { impl.start(); } return true; }
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(...); Clip clip = AudioSystem.getClip(); clip.open(audioInputStream); clip.loop(Clip.LOOP_CONTINUOUSLY); clip.start();
public void play() { if (SoundManager.isSoundEnabled()) { clip.setFramePosition(0); clip.loop(0); } } }
... Clip clip = (Clip) AudioSystem.getLine(info); clip.open(af, audio, 0, size); clip.loop(3); //Added this line clip.setLoopPoints(0, -1); //Added this line clip.start(); ...