Package javax.sound.sampled

Examples of javax.sound.sampled.Clip


 
  //for looping wav clips
  //http://stackoverflow.com/questions/4875080/music-loop-in-java
  public static Clip clipForLoopFactory(String strPath){
   
    Clip clp = null;
   
    // this line caused the original exceptions
   
    try {
      AudioInputStream aisStream =
            AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream(strPath));
      clp = AudioSystem.getClip();
        clp.open( aisStream );
       
    } catch (UnsupportedAudioFileException exp) {
     
      exp.printStackTrace();
    } catch (IOException exp) {
View Full Code Here


        if ( current != null ) {
            current.close();
        }
        try {
            Clip c = AudioSystem.getClip();
            c.open(format,data,0,data.length);
            current = c;
            c.loop(Clip.LOOP_CONTINUOUSLY);
            System.out.println("Playing " + freq);
        }
        catch ( Exception e ) {
            e.printStackTrace();
        }
View Full Code Here

        if ( current != null ) {
            current.close();
        }
        try {
            Clip c = AudioSystem.getClip();
            c.open(format,data,0,data.length);
            current = c;
            c.loop(Clip.LOOP_CONTINUOUSLY);
            System.out.println("Playing " + start + " to " + end + " for " + time + "s");
        }
        catch ( Exception e ) {
            e.printStackTrace();
        }
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

    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

        }
        catch(ClassCastException e)
        {
          try
          {
            Clip sClip = (Clip)mixer.getLine(sLineInfos[k]);
            System.out.println("   Clip: " + sClip.getLineInfo() + "\t(Name: " + sClip + ")");
          }
          catch (LineUnavailableException e1)
          {
            e1.printStackTrace();
          }
          catch(ClassCastException e1)
          {
            try
            {
              Port sPort = (Port)mixer.getLine(sLineInfos[k]);
              System.out.println("   Port: " + sPort.getLineInfo() + "\t(Name: " + sPort + ")");
            }
            catch (LineUnavailableException e2)
            {
              e2.printStackTrace();
            }
          }
        }
       
      }
     
      Line.Info[] tLineInfos = mixer.getTargetLineInfo();
      System.out.println("  Targets (" + tLineInfos.length + "):");
      for(int k=0; k<tLineInfos.length; k++)
      {
        try
        {
          TargetDataLine tLine = (TargetDataLine)mixer.getLine(tLineInfos[k]);
          System.out.println("   Line: " + tLine.getLineInfo() + "\t(Name: " + tLine + ")");
        }
        catch (LineUnavailableException e)
        {
          e.printStackTrace();
        }
        catch(ArrayIndexOutOfBoundsException e)
        {
         
        }
        catch(ClassCastException e)
        {
          try
          {
            Clip tClip = (Clip)mixer.getLine(tLineInfos[k]);
            System.out.println("   Clip: " + tClip.getLineInfo() + "\t(Name: " + tClip + ")");
          }
          catch (LineUnavailableException e1)
          {
            e1.printStackTrace();
          }
View Full Code Here

    public void testCreateAndPlayClip() throws Exception
    {
      InputStream bell = getClass().getResourceAsStream("Bell1_1s.wav");
      assertNotNull(bell);
      Clip clip = ClipBooster.createClip(bell);
      ClipBooster.playClipFromBeginning(clip, 1);
    }
View Full Code Here

   * @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();
    result.open(AudioSystem.getAudioInputStream(inputstream));
    return result;
  }
View Full Code Here

    @Test
    public void testCreateAndPlayClip() throws Exception
    {
      InputStream bell = getClass().getResourceAsStream("Bell1_1s.wav");
      assertNotNull(bell);
      Clip clip = ClipBooster.createClip(bell);
      RunnableClip runnable = new RunnableClip(clip);
      ThreadBoostUtils.run(runnable, 1000);
      //ClipBooster.playClipFromBeginning(clip, 1);
    }
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.