public int getMillisecondLength() { return (int)c.getMicrosecondLength() / 1000; }
public long getTamanhoMusica() { return clip.getMicrosecondLength(); }
@Nonnull @Override public Duration getDuration() { return Duration.ofNanos(TimeUnit.MICROSECONDS.toNanos(clip.getMicrosecondLength())); }
URL url = new URL("foo.wav"); Clip clip = AudioSystem.getClip(); AudioInputStream ais = AudioSystem.getAudioInputStream(url); clip.open(ais); System.out.println(clip.getMicrosecondLength());
Clip clip = AudioSystem.getClip(); clip.open(AudioSystem.getAudioInputStream(new File("water-splash.wav"))); clip.start(); int lengthInMilliseconds = clip.getMicrosecondLength() * 1000; Thread.sleep(lengthInMilliseconds);
public static void main(String[] args) { Clip c=loadClip("mikera/sound/Thud.wav"); try { c.start(); Thread.sleep(1000); c.start(); Thread.sleep(c.getMicrosecondLength()/1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public void play() { if ( c.getMicrosecondPosition() != c.getMicrosecondLength() ) { c.start(); playing = true; } }
class sound implements Runnable { @Override public void run() { Clip clip = null; // take the declaration of the clip variable out of the try - catch try { AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("/Users/babe/Desktop/Con1.wav").getAbsoluteFile()); clip = AudioSystem.getClip(); clip.open(audioInputStream); clip.start(); Thread.sleep(clip.getMicrosecondLength() / 1000); } catch(InterruptedException ex) { clip.stop(); // <--- ADD THIS LINE System.out.println("Cancelled 1!"); } catch (Exception ex) { System.out.println("Error with playing sound."); ex.printStackTrace(); } } }
clip.open(audioInputStream); clip.start(); Thread.sleep(clip.getMicrosecondLength() / 1000); } catch(InterruptedException ex) { System.out.println("Cancelled!");
public void play(InputStream inputStream) { try { AudioInputStream soundIn = AudioSystem.getAudioInputStream(new BufferedInputStream(inputStream) ); AudioFormat format = soundIn.getFormat(); DataLine.Info info = new DataLine.Info(Clip.class, format); Clip clip = (Clip) AudioSystem.getLine(info); clip.open(soundIn); clip.start(); sleep(clip.getMicrosecondLength() / 1000);// Thread.yield(); } catch (Exception e) { log.warn("could not play"); e.printStackTrace(); } } private void sleep(long sleep) { try { Thread.sleep(sleep); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } }
/** * Play a wav file. Must be mono, from 8kHz to 48kHz, and 8-bit or 16-bit. * @param file the 8-bit or 16-bit PWM (WAV) sample file */ public void playSample(final File file) { try (AudioInputStream audioIn = AudioSystem.getAudioInputStream(file.toURI().toURL())) { Clip clip = AudioSystem.getClip(); clip.open(audioIn); clip.start(); Delay.usDelay(clip.getMicrosecondLength()); clip.close(); } catch (IOException | LineUnavailableException | UnsupportedAudioFileException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new RuntimeException(e); } }
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(); }
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(); } }
timerUpdate = true; try { long length = TimeUnit.NANOSECONDS.convert(clip.getMicrosecondLength(), TimeUnit.SECONDS); long time = TimeUnit.NANOSECONDS.convert(clip.getMicrosecondPosition(), TimeUnit.SECONDS); int progress = (int) Math.round(((double) time / (double) length) * 100d); userUpdate = true; try { long length = clip.getMicrosecondLength(); int progress = slider.getValue(); long time = (long) (length * (progress / 100d));
audioLength = (int) (clip.getMicrosecondLength() / 1000);
clip.open(stream); clip.start(); while(clip.getMicrosecondLength() != clip.getMicrosecondPosition()) {}
while(clip.getMicrosecondLength() != clip.getMicrosecondPosition()){
Clip clip = AudioSystem.getClip(); clip.open(inputAIS); long totalMicroSecond = clip.getMicrosecondLength(); } catch (UnsupportedAudioFileException e) {
meta = new BasicMetaData(filename, clip.getMicrosecondLength() / 1000, -1);