Package javax.sound.sampled

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


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

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

    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

    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

   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

        {
            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

        {
            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

   */
  public void playEvent(String event) {
    if (soundEvents.containsKey(event)) {
      Object sound = soundEvents.get(event);
      if (sound instanceof Clip) {
        Clip clip = (Clip) sound;
        clip.setFramePosition(0);
        clip.start();
      } else if (sequencer != null && sound instanceof Sequence) {
        Sequence sequence = (Sequence) sound;
        try {
          sequencer.setSequence(sequence);
          sequencer.start();
View Full Code Here

  public void loopEvent(String event) {
    if (soundEvents.containsKey(event)) {
      Object sound = soundEvents.get(event);
      if (sound instanceof Clip) {
        Clip clip = (Clip) sound;
        clip.setFramePosition(0);
        clip.loop(Clip.LOOP_CONTINUOUSLY);
        clip.start();
        looping = clip;
      } else if (sequencer != null && sound instanceof Sequence) {
        playEvent(event);
        looping = sound;
      }
View Full Code Here

  }

  public void stopLooping() {
    if (looping != null) {
      if (looping instanceof Clip) {
        Clip clip = (Clip) looping;
        clip.stop();
      } else if (sequencer != null && looping instanceof Sequence) {
        sequencer.stop();
      }
      looping = null;
    }
View Full Code Here

TOP

Related Classes of javax.sound.sampled.Clip

Copyright © 2018 www.massapicom. 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.