Refine search
/** * Plays a sound from a file. * * @param filename Path to the sound file */ public static void playSound(String filename) { URL resource = ClassLoader.getSystemClassLoader().getResource(filename); try { final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class)); clip.addLineListener(event -> { if (event.getType() == LineEvent.Type.STOP) { clip.close(); } }); clip.open(AudioSystem.getAudioInputStream(resource)); clip.start(); } catch (Exception e) { LOGGER.error("Failed to play sound " + filename, e); } }
private boolean done = false; @Override public synchronized void update(LineEvent event) { Type eventType = event.getType(); if (eventType == Type.STOP || eventType == Type.CLOSE) { done = true; Clip clip = AudioSystem.getClip(); clip.addLineListener(listener); clip.open(audioInputStream); try { clip.start();
clip.addLineListener(new LineListener() { @Override public void update(LineEvent event) { if (event.getType() == Type.START) synchronized (clip) { clip.notify(); b[i] = (byte) (50*Math.sin(i/10.0)); clip.open(format, b, 0, b.length); clip.setFramePosition(0);
private static boolean play(final InputStream arquivo, int count) { try (final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(arquivo)) { // Carrega o formato do audio e cria uma linha final AudioFormat audioFormat = audioInputStream.getFormat(); final DataLine.Info dataLineInfo = new DataLine.Info(Clip.class, audioInputStream.getFormat(), (int) audioInputStream.getFrameLength() * audioFormat.getFrameSize()); // Carrega o som para o dispositivo try (final Clip clip = (Clip) AudioSystem.getLine(dataLineInfo)) { // Evento do LineListener clip.addLineListener(e -> { if (LineEvent.Type.STOP.equals(e.getType())) { e.getLine().close(); } }); clip.open(audioInputStream); clip.loop(count); } return true; } catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) { LogUtils.generate(e); return false; } } }
audioLineClip.open(inputStream); audioLineClip.setFramePosition(0); @Override public void update(LineEvent event) { LineEvent.Type type = event.getType(); if (type == LineEvent.Type.OPEN) { } else if (type == LineEvent.Type.CLOSE) { break; case Loop: audioLineClip.loop(Clip.LOOP_CONTINUOUSLY); break;
@Override public void update(LineEvent event) { System.out.println(event.getFramePosition()); if (event.getType().equals(LineEvent.Type.STOP)) { setEnabled(true); play.open(audioInputStream); play.start(); } catch (IOException | LineUnavailableException | UnsupportedAudioFileException exp) {
@Override public void update(LineEvent event) { if (event.getType().equals(Type.START)) { play.setText("||"); } else if (event.getType().equals(Type.OPEN)) { System.out.println("Open"); } else if (event.getType().equals(Type.STOP)) { play.setText(">"); } else if (event.getType().equals(Type.CLOSE)) { play.setText(">"); clip.stop(); } else { if (lastFrame < clip.getFrameLength()) { clip.setFramePosition(lastFrame); } else { clip.setFramePosition(0);
try { clips[sound][i] = AudioSystem.getClip(); clips[sound][i].open(loadSound(sound)); clips[sound][i].addLineListener(new LineListener(){ if(event.getType() == javax.sound.sampled.LineEvent.Type.STOP){ clips[sound][clipIndex[sound]].setFramePosition(0); clips[sound][clipIndex[sound]].setFramePosition(0);
@Override public void update (final LineEvent event) { final LineEvent.Type type = event.getType (); if (type == LineEvent.Type.STOP) { synchronized (clip) { if (stopMonitor != null) { synchronized (stopMonitor) { stopMonitor.notifyAll (); } } if (event.getFramePosition () != -1) { clip.stop (); clip.close (); clip.notifyAll (); } } } }
public void update(LineEvent event) { if ( event.getType().equals( LineEvent.Type.STOP ) ) { if ( playing && loopCount != 0 ) { c.setMicrosecondPosition( 0 ); c.start(); if ( loopCount > 0 ) { loopCount--; } } else { playing = false; } } } } );
info = new DataLine.Info(Clip.class, format); clip = (Clip) AudioSystem.getLine(info); clip.open(stream); clip.start(); while(clip.getMicrosecondLength() != clip.getMicrosecondPosition()){ if (myLineEvent.getType() == LineEvent.Type.STOP) clip.close();
@Override public void update(LineEvent event) { if(event.getType().equals(LineEvent.Type.STOP)) { closeClip(); chain.playNextSound(); } }
public void update(LineEvent event) { if (event.getType() != STOP) return; clip.removeLineListener(clipListener); clip = null; synchronized (notificationMutex) { playing = false; notificationMutex.notifyAll(); } } };
protected void notifyLineEvent(LineEvent.Type type) { notifyLineEvent(new LineEvent(this, type, AudioSystem.NOT_SPECIFIED)); }