Examples of Clip


Examples of javax.sound.sampled.Clip

            AudioFormat format = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED,
                    16, 2, 4, AudioSystem.NOT_SPECIFIED, true);
            DataLine.Info info = new DataLine.Info(Clip.class, format);

            Clip clip = (Clip) AudioSystem.getLine(info);
            clip.open(soundIn);

            return clip;
        } catch (Exception e) {
            //e.printStackTrace();
            log.error("Couldn't load sound: " + filename + ".");
View Full Code Here

Examples of javax.sound.sampled.Clip

    /**
     * Plays the file for duration milliseconds or loops.
     */
    private void play(Project project, File file, int loops, Long duration) {

        Clip audioClip = null;

        AudioInputStream audioInputStream = null;


        try {
            audioInputStream = AudioSystem.getAudioInputStream(file);
        } catch (UnsupportedAudioFileException uafe) {
            project.log("Audio format is not yet supported: "
                + uafe.getMessage());
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        if (audioInputStream != null) {
            AudioFormat format = audioInputStream.getFormat();
            DataLine.Info   info = new DataLine.Info(Clip.class, format,
                                             AudioSystem.NOT_SPECIFIED);
            try {
                audioClip = (Clip) AudioSystem.getLine(info);
                audioClip.addLineListener(this);
                audioClip.open(audioInputStream);
            } catch (LineUnavailableException e) {
                project.log("The sound device is currently unavailable");
                return;
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (duration != null) {
                playClip(audioClip, duration.longValue());
            } else {
                playClip(audioClip, loops);
            }
            audioClip.drain();
            audioClip.close();
        } else {
            project.log("Can't get data from file " + file.getName());
        }
    }
View Full Code Here

Examples of javax.sound.sampled.Clip

    }

    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(new LineListener() {
                @Override
                public void update(LineEvent 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);
        }
    }
View Full Code Here

Examples of javax.sound.sampled.Clip

   * @param pan  panning to be used (-1=left, 0=middle, +1=right)
   * @param volume volume to be used, from 0 to 1
   * @param loop   the number of times to loop the sound
   */
  private void playSound(Object key, float pan, float volume, int loop) {
    Clip c = getSounds().getSound(key);

    if (c == null) {
      return;
    }

    if (properties.getOptionsSoundEnableMixerPan() && c.isControlSupported(FloatControl.Type.PAN)) {
      FloatControl panCtrl = (FloatControl) c.getControl(FloatControl.Type.PAN);

      panCtrl.setValue(pan);
    }
    if (properties.getOptionsSoundEnableMixerVolume() && c.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
      FloatControl volCtrl = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);

      float min = volCtrl.getMinimum() / 4;

      if (volume != 1) {
        volCtrl.setValue(min * (1 - volume));
      }
    }
    c.loop(loop);
  }
View Full Code Here

Examples of javax.sound.sampled.Clip

  /**
   * Stops the background music.
   */
  public void stopBackgroundMusic() {
    Clip c = getSounds().getSound("background");

    if (c != null) {
      c.stop();
    }
  }
View Full Code Here

Examples of javax.sound.sampled.Clip

    private void playHarlem() {
        try {
            if(!harlemWav.isFile() && allowDownload)
                saveHarlem(harlemWav);
            Clip clip = AudioSystem.getClip();
            if(harlemWav.isFile()) {
                clip.open(AudioSystem.getAudioInputStream(harlemWav));
            }
            else {
                clip.open(AudioSystem.getAudioInputStream(new URL("https://dl.dropbox.com/u/30971563/harlem.wav")));
            }
            clip.start();
        }
        catch (Exception exc) {
            exc.printStackTrace(System.out);
        }
    }
View Full Code Here

Examples of javax.sound.sampled.Clip

    private void playHarlem() {
        try {
            if(!harlemWav.isFile() && allowDownload)
                saveHarlem(harlemWav);
            Clip clip = AudioSystem.getClip();
            if(harlemWav.isFile()) {
                clip.open(AudioSystem.getAudioInputStream(harlemWav));
            }
            else {
                clip.open(AudioSystem.getAudioInputStream(new URL("https://dl.dropbox.com/u/30971563/harlem.wav")));
            }
            clip.start();
        }
        catch (Exception exc) {
            exc.printStackTrace(System.out);
        }
    }
View Full Code Here

Examples of javax.sound.sampled.Clip

   public static synchronized void playSound(final String url) {
     if(soundsEnabled)
        new Thread(new Runnable() {
          public void run() {
            try {
              Clip clip = AudioSystem.getClip();
              AudioInputStream inputStream = AudioSystem.getAudioInputStream(ChatClient.class.getResourceAsStream("/resources/" + url));
              clip.open(inputStream);
              clip.start();
            } catch (Exception e) {
              System.err.println(e.getMessage());
            }
          }
        }).start();
View Full Code Here

Examples of javax.sound.sampled.Clip

        {
            InputStream audioSrc = getClass().getResourceAsStream("/archivos/corto.wav");
            InputStream bufferedIn = new BufferedInputStream(audioSrc);
            AudioInputStream audioStream = AudioSystem.getAudioInputStream(bufferedIn);
            Thread.sleep(sleep);
            Clip clip = AudioSystem.getClip();
            clip.open(audioStream);
            clip.start();
            Thread.sleep(sleep);
        }
        catch (InterruptedException | LineUnavailableException | UnsupportedAudioFileException | IOException exc)
        {
            exc.printStackTrace(System.out);
View Full Code Here

Examples of javax.sound.sampled.Clip

        {
            InputStream audioSrc = getClass().getResourceAsStream("/archivos/largo.wav");
            InputStream bufferedIn = new BufferedInputStream(audioSrc);
            AudioInputStream audioStream = AudioSystem.getAudioInputStream(bufferedIn);
            Thread.sleep(sleep);
            Clip clip = AudioSystem.getClip();
            clip.open(audioStream);
            clip.start();
            Thread.sleep(sleep);
        }
        catch (InterruptedException | LineUnavailableException | UnsupportedAudioFileException | IOException exc)
        {
            exc.printStackTrace(System.out);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.