Package javax.sound.sampled

Examples of javax.sound.sampled.Clip


    }
   
    if (currentSound != null) {
      if (currentSound instanceof AudioInputStream) {
        try {
          Clip clip = (Clip) AudioSystem.getLine(new Info(Clip.class, ((AudioInputStream) currentSound).getFormat()));
          clip.open((AudioInputStream) currentSound);
          soundEvents.put(destination, clip);
        } catch (LineUnavailableException e1) {
          // This will happen if the underlying platform does not support sound
          // System.err.println(e1.getMessage());
          // e1.printStackTrace();
View Full Code Here


      return clip;
    }

    public void loop()
    {
      Clip myclip = getClip();
      if (myclip != null)
        myclip.loop(Clip.LOOP_CONTINUOUSLY);
    }
View Full Code Here

        myclip.loop(Clip.LOOP_CONTINUOUSLY);
    }

    public void play()
    {
      Clip myclip = getClip();
      if (myclip != null)
        myclip.start();
    }
View Full Code Here

        myclip.start();
    }

    public void stop()
    {
      Clip myclip = getClip();
      if (myclip != null)
        {
          myclip.stop();
          myclip.setFramePosition(0);
        }
    }
View Full Code Here

      return clip;
    }

    public void loop()
    {
      Clip myclip = getClip();
      if (myclip != null)
        myclip.loop(Clip.LOOP_CONTINUOUSLY);
    }
View Full Code Here

        myclip.loop(Clip.LOOP_CONTINUOUSLY);
    }

    public void play()
    {
      Clip myclip = getClip();
      if (myclip != null)
        myclip.start();
    }
View Full Code Here

        myclip.start();
    }

    public void stop()
    {
      Clip myclip = getClip();
      if (myclip != null)
        {
          myclip.stop();
          myclip.setFramePosition(0);
        }
    }
View Full Code Here

            return null;
        }

        final AudioFormat format = audioInputStream.getFormat();

        final Clip clip;
        try {
            DataLine.Info info = new DataLine.Info(Clip.class, format);
            clip = (Clip) AudioSystem.getLine(info);
            clip.open(audioInputStream);
        } catch (LineUnavailableException e) {
            System.out.println("Sorry, sound is not available");
            return null;
        } catch (IOException e) {
            return null;
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();
    //add buffer for mark/reset support
    InputStream bufferedInput = new BufferedInputStream(inputstream);
   
    result.open(AudioSystem.getAudioInputStream(bufferedInput));
    return result;
  }
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

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.