public int getMillisecondPosition() { return (int)c.getMicrosecondPosition() / 1000; }
public long getPosicaoAtualMusica() { if(clipTime>0) { return clipTime; } return clip.getMicrosecondPosition(); }
@Nonnull @Override public Duration getPosition() { if (isPlaying()) { return Duration.ofNanos(TimeUnit.MICROSECONDS.toNanos(clip.getMicrosecondPosition())); } return null; }
/** * Calculates the number of milliseconds since the channel began playing. * @return Milliseconds, or -1 if unable to calculate. */ @Override public float millisecondsPlayed() { switch( channelType ) { case SoundSystemConfig.TYPE_NORMAL: if( clip == null ) return -1; return clip.getMicrosecondPosition() / 1000f; case SoundSystemConfig.TYPE_STREAMING: if( sourceDataLine == null ) return -1; return sourceDataLine.getMicrosecondPosition() / 1000f; default: return -1; } } /**
void tick() { if (clip.isActive()) { audioPosition = (int) (clip.getMicrosecondPosition() / 1000); progress.setValue(audioPosition); } else { reset(); } }
public void play() { if ( c.getMicrosecondPosition() != c.getMicrosecondLength() ) { c.start(); playing = true; } }
class TestFramePosition { public static void main(String[] a) throws Exception { File file = new File(a.length > 0 ? a[0] : "path/to/file.extension"); AudioInputStream ais = AudioSystem.getAudioInputStream(file); final Clip clip = AudioSystem.getClip(); clip.open(ais); clip.start(); new Thread(new Runnable() { @Override public void run() { while(clip.isRunning()) { try { System.out.println(clip.getMicrosecondPosition()); Thread.sleep(1000 / 10); } catch(InterruptedException ignored) {} } } }).start(); System.in.read(); System.exit(0); } }
String filename="foo.wav"; Clip clip=AudioSystem.getClip(); AudioInputStream inputStream=AudioSystem.getAudioInputStream(new BufferedInputStream(Audio.class.getResourceAsStream(filename))); if(inputStream!=null) { clip.open(inputStream); FloatControl gainControl=(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(+6.0f); // ? clip.start(); // maybe do not wait? while(clip.getMicrosecondLength()!=clip.getMicrosecondPosition()) Thread.yield(); // wait // or at least don't wait here? Thread.sleep(500); clip.close(); }
public void pausa(boolean fechaClip) { if (clip == null) { return; } clipTime=clip.getMicrosecondPosition(); clip.stop(); clip.flush(); if (fechaClip) { clip.close(); } }
private void playClip(Clip clip, int loops) { clip.loop(loops); do { try { long timeLeft = (clip.getMicrosecondLength() - clip.getMicrosecondPosition()) / 1000; if (timeLeft > 0) { Thread.sleep(timeLeft); } } catch (InterruptedException e) { break; } } while (clip.isRunning()); if (clip.isRunning()) { clip.stop(); } }