public void run() { System.err.println("Timer task running"); if (!clip.isActive() // already stopped? || clip.getFramePosition() >= endFrame) { System.err.println("Timer task stopping clip."); clip.stop(); this.cancel(); } } }
public void run() { System.err.println("Timer task running"); if (!clip.isActive() // already stopped? || clip.getFramePosition() >= endFrame) { System.err.println("Timer task stopping clip."); clip.stop(); this.cancel(); } } }
public void actionPerformed(ActionEvent e) { synchronized (clip) { if (clip.isActive()) { System.err.println("Stopping clip."); clip.stop(); } else { System.err.println("Rewinding clip."); if (Double.isNaN(positionCursor.x)) { // no cursor, play from start clip.setFramePosition(0); } else { // play from cursor position clip.setFramePosition(X2indexX(positionCursor.x)); } if (!Double.isNaN(rangeCursor.x)) { // range set? System.err.println("Setting timer task"); int endFrame = X2indexX(rangeCursor.x); timer.schedule(new ClipObserver(clip, endFrame), 50, 50); } System.err.println("Starting clip."); clip.start(); } } } });
public void actionPerformed(ActionEvent e) { synchronized (clip) { if (clip.isActive()) { System.err.println("Stopping clip."); clip.stop(); } else { System.err.println("Rewinding clip."); if (Double.isNaN(positionCursor.x)) { // no cursor, play from start clip.setFramePosition(0); } else { // play from cursor position clip.setFramePosition(X2indexX(positionCursor.x)); } if (!Double.isNaN(rangeCursor.x)) { // range set? System.err.println("Setting timer task"); int endFrame = X2indexX(rangeCursor.x); timer.schedule(new ClipObserver(clip, endFrame), 50, 50); } System.err.println("Starting clip."); clip.start(); } } } });
@Override protected boolean playingImpl() { return impl.isActive(); }
@Override protected boolean playingImpl() { return impl.isActive(); }
@Override protected boolean playingImpl() { return impl.isActive(); }
@Override protected boolean playingImpl() { return impl.isActive(); }
@Override // TODO Gambiarra... public boolean isPlaying() { /* Workaround, since after clip.start() the sound have a small delay before starting to act. Used on Sound.waitUntilDone(). */ if (justPlayed != 0L) { if (XSystem.millis() - justPlayed <= 150L) { return true; } this.justPlayed = 0L; } return clip != null && clip.isActive(); }
void tick() { if (clip.isActive()) { audioPosition = (int) (clip.getMicrosecondPosition() / 1000); progress.setValue(audioPosition); } else { reset(); } }
/** * Used to determine if a channel is actively playing a source. This method * will return false if the channel is paused or stopped and when no data is * queued to be streamed. * @return True if this channel is playing a source. */ @Override public boolean playing() { switch( channelType ) { case SoundSystemConfig.TYPE_NORMAL: if( clip == null ) return false; return clip.isActive(); case SoundSystemConfig.TYPE_STREAMING: if( sourceDataLine == null ) return false; return sourceDataLine.isActive(); default: return false; } } }
if (clip.isActive()) {
public static synchronized void playSound(final String folder, final String name) { new Thread(new Runnable() { // the wrapper thread is unnecessary, unless it blocks on the Clip finishing, see comments @Override public void run() { Clip clip = null; AudioInputStream inputStream = null; try{ do{ if(clip == null || inputStream == null){ clip = AudioSystem.getClip(); } inputStream = AudioSystem.getAudioInputStream(SoundP.class.getResource(folder + "/" + name)); if(clip != null && !clip.isActive()){ inputStream = AudioSystem.getAudioInputStream(SoundP.class.getResource(folder + "/" + name)); } clip.open(inputStream); clip.start(); }while(clip.isActive()); inputStream.close(); } catch (LineUnavailableException e) { e.printStackTrace(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }).start(); }
/** * Plays the loaded audio file if sound is enabled, and * it's not already playing. If nothing has been played for * 5 seconds the sound resource is released. */ public synchronized void beep() { if (settings.isSound()) { if (audioClip == null || !audioClip.isActive()) { if (audioClip == null) { open(); } else { audioClip.setFramePosition(0); } if (audioClip != null) { audioClip.start(); closeTime = System.currentTimeMillis() + WAIT_PERIOD; if (closeTimer == null) { closeTimer = new Thread(new CloseTimer(), "SoundBeeperCloseTimer"); closeTimer.start(); } } else { LOG.log(Level.SEVERE, "Audio clip missing."); } } } }
public void run() { // set gain FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); double value = volume / 20.0; float dB = (float) (Math.log(value==0.0?0.0001:value)/Math.log(10.0)*20.0); gainControl.setValue(dB); Trace.trace(Trace.FINEST, "start"); clip.start(); try { sleep(99); } catch (Exception e) { // ignore } while (clip.isActive()) { try { sleep(99); } catch (Exception e) { break; } } clip.stop(); clip.close(); Trace.trace(Trace.FINEST, "stop"); } };