Java 8 Clip - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Clip class.

This code example shows how to use the following methods:loop, open, drain
6
CodeRank
This code example shows how to use the following methods:open, drain, addLineListener, close
            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();

6
CodeRank
This code example shows how to use the following methods:drain, flush, close
 
    public void close() 
    { 
        try 
        { 
            this.clip.drain();
            this.clip.flush();
            this.clip.close();
        } 
        catch (Exception e)
        { 
            LogUtil.put(LogFactory.getInstance( 
                "Exception", this, "close", e));
        } 
    } 
 
    public String getContentType()
    { 
        return null; 
    } 
5
CodeRank
This code example shows how to use the following methods:loop, setFramePosition, start
 
    public synchronized void start() throws MediaException 
    { 
        try 
        { 
            this.clip.setFramePosition(0);
            this.clip.loop(this.getLoopCount());
            this.clip.start();
            super.start(); 
        } 
        catch (Exception e)
        { 
            LogUtil.put(LogFactory.getInstance( 
                "Exception", this, "start", e));
        } 
    } 
 
    private final Clip create()
        throws Exception
5
CodeRank
This code example shows how to use the following methods:loop, setFramePosition
        this.clip = clip;
    } 
 
    public void play() { 
        if (SoundManager.isSoundEnabled()) { 
            clip.setFramePosition(0);
            clip.loop(0);
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:open, start
        AudioInputStream playAIS = getSelectedAudio();
        System.out.println("Playing from "+tStart+" to "+tEnd);
        try { 
            DataLine.Info clipInfo = new DataLine.Info(Clip.class, audioFormat);
            Clip clip = (Clip) AudioSystem.getLine(clipInfo);
            clip.open(playAIS);
            clip.start();
        } catch (Exception e) {
            e.printStackTrace();
        } 
    } 
     
    private void saveCurrentSelection() 
    { 
        System.out.println("Saving current selection");
        if (!delimitSelection()) return; 
        // Now we have valid start and end times 
        File saveWav = new File(extractedWavDir, saveFilename.getText()+db.getProp(db.WAVEXT));
        File saveLab = new File(extractedLabDir, saveFilename.getText()+db.getProp(db.LABEXT));
        AudioInputStream selectedAudio = getSelectedAudio();
5
CodeRank
This code example shows how to use the following methods:open, drain, addLineListener, close
            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();

5
CodeRank
This code example shows how to use the following methods:setFramePosition, flush, isRunning, start, stop
		if (clip == null)  // clip failed to load properly
			return; 
 
		if (volume > 0f) {
			// stop clip if running 
			if (clip.isRunning()) {
				clip.stop();
				clip.flush();
			} 
 
			// PulseAudio does not support Master Gain 
			if (clip.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
				// set volume 
				FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
				float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0);
				gainControl.setValue(dB);
			} 
 
			// play clip 
			clip.setFramePosition(0);

5
CodeRank
This code example shows how to use the following methods:setFramePosition, isActive, start, stop
	/** 
	 * Starts playing the audio clip from the beginning. If it is already 
	 * playing, the clip is stopped and restarted. 
	 */ 
	public void start() { 
		if (clip.isActive()) {
			clip.stop();
		} 
 
		clip.setFramePosition(0);
		clip.start();
	} 
} 
5
CodeRank
This code example shows how to use the following methods:getFormat
   * @param clip Clip The Clip used to configure the BigClip. 
   */ 
  public BigClip (Clip clip)
    throws LineUnavailableExceptiondataLine = AudioSystem.getSourceDataLine(clip.getFormat());
  } 
 
  /** 
   * Provides the entire audio buffer of this clip. 
   * @return audioData byte[] The bytes of the audio data that is loaded in this Clip. 
   */ 
  public byte[] getAudioData () 
  { 
    return audioData;
  } 
 
  /** Converts a frame count to a duration in milliseconds. */ 
  private long convertFramesToMilliseconds (int frames)
  { 
4
CodeRank
See Code Examples for Java 8 Clip Methods: