Package javax.sound.sampled

Examples of javax.sound.sampled.Clip


   * @throws LineUnavailableException  forwarded from the underlying code
   * @throws UnsupportedAudioFileException  forwarded from the underlying code
   */
  public static Clip createClip(InputStream inputstream) throws IOException, LineUnavailableException, UnsupportedAudioFileException
  {
    Clip result = AudioSystem.getClip();
    //add buffer for mark/reset support
    InputStream bufferedInput = new BufferedInputStream(inputstream);
   
    result.open(AudioSystem.getAudioInputStream(bufferedInput));
    return result;
  }
View Full Code Here


{

  public Clip createSampleClip() throws Exception {
    InputStream bell = getClass().getResourceAsStream("Bell1_1s.wav");
    assertNotNull(bell);
    Clip clip = AudioBoostUtils.createClip(bell);
    return clip;

  }
View Full Code Here

  }

    @Test
  public void testCreateClip() throws Exception
    {
    Clip clip = createSampleClip();
    assertNotNull(clip);
    }
View Full Code Here


    @Test
    public void testCreateAndPlayClip() throws Exception
    {
    Clip clip = new AudioBoostUtilsTest().createSampleClip();
      RunnableClip runnable = new RunnableClip(clip);
      ThreadBoostUtils.run(runnable, 1000);
    }
View Full Code Here

    void beep() {
        if (config.getBeep_alert()) {
            try {
                BufferedInputStream fileInStream = new BufferedInputStream(Client.class.getClassLoader().getResource("beep.wav").openStream());
                AudioInputStream beepStream = AudioSystem.getAudioInputStream(fileInStream);
                Clip c = AudioSystem.getClip();
                c.open(beepStream);
                c.start();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
View Full Code Here

    public synchronized void playSound() {
        new Thread(new Runnable() {
            public void run() {
                try {
                    Clip clip = AudioSystem.getClip();
                    AudioInputStream effectStream = AudioSystem
                            .getAudioInputStream(new ByteArrayInputStream(
                                    GameManager.this.reactorEffectRawData));
                    clip.open(effectStream);
                    clip.start();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
View Full Code Here

/* 145 */     if (this.ais == null)
/*     */     {
/* 150 */       return false;
/*     */     }
/*     */
/* 154 */     Clip leftLine = this.line;
/* 155 */     Clip rightLine = this.otherChannel;
/*     */
/* 170 */     double ZERO_EPS = 0.0039D;
/* 171 */     double leftVolume = leftGain;
/* 172 */     double rightVolume = rightGain;
/*     */
View Full Code Here

            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

    /**
     * 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

    }

    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

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.