javax.sound.sampled.Clip.loop()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中javax.sound.sampled.Clip.loop()方法的一些代码示例,展示了Clip.loop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clip.loop()方法的具体详情如下:
包路径:javax.sound.sampled.Clip
类名称:Clip
方法名:loop

Clip.loop介绍

暂无

代码示例

代码示例来源:origin: kevin-wayne/algs4

/**
 * Loops an audio file (in .wav, .mid, or .au format) in a background thread.
 *
 * @param filename the name of the audio file
 * @throws IllegalArgumentException if {@code filename} is {@code null}
 */
public static synchronized void loop(String filename) {
  if (filename == null) throw new IllegalArgumentException();
  // code adapted from: http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java
  try {
    Clip clip = AudioSystem.getClip();
    InputStream is = StdAudio.class.getResourceAsStream(filename);
    AudioInputStream ais = AudioSystem.getAudioInputStream(is);
    clip.open(ais);
    clip.loop(Clip.LOOP_CONTINUOUSLY);
  }
  catch (UnsupportedAudioFileException e) {
    throw new IllegalArgumentException("unsupported audio format: '" + filename + "'", e);
  }
  catch (LineUnavailableException e) {
    throw new IllegalArgumentException("could not play '" + filename + "'", e);
  }
  catch (IOException e) {
    throw new IllegalArgumentException("could not play '" + filename + "'", e);
  }
}

代码示例来源:origin: marytts/marytts

e.printStackTrace();
m_clip.loop(loop);
if (waitUntilCompleted)
  m_clip.drain();

代码示例来源:origin: marytts/marytts

e.printStackTrace();
m_clip.loop(loop);
if (waitUntilCompleted)
  m_clip.drain();

代码示例来源:origin: stackoverflow.com

import java.io.File;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class Snippet {
  public static void main(String[] args) throws Exception {

    AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("notify.wav"));
    Clip clip = AudioSystem.getClip();
    clip.open(inputStream);
    clip.loop(Clip.LOOP_CONTINUOUSLY);
    Thread.sleep(10000); // looping as long as this thread is alive
  }
}

代码示例来源:origin: stackoverflow.com

clip.loop(Clip.LOOP_CONTINUOUSLY);

代码示例来源:origin: tomighty/tomighty

private SoundChain play(final Sound sound, boolean repeatedly, final SoundChain chain) {
  stop(sound);
  if(sound.disabled()) {
    chain.takeOver();
    return chain;
  }
  try {
    InputStream stream = sound.inputStream();
    //wrap the stream in another one that supports mark/reset (see issue #31)
    stream = new BufferedInputStream(stream);
    AudioInputStream input = AudioSystem.getAudioInputStream(stream);
    Clip clip = AudioSystem.getClip();
    clip.addLineListener(new ClipHandler(sound, chain));
    clip.open(input);
    if(repeatedly) {
      clip.loop(Clip.LOOP_CONTINUOUSLY);
    } else {
      clip.start();
    }
    activeClips.put(sound, clip);
  } catch (Exception e) {
    logger.error("Error while playing sound: " + sound, e);
  }
  return chain;
}

代码示例来源:origin: stackoverflow.com

clip.loop( loopcount );
if ( commence ) {
  clip.setFramePosition(0);
  clip.loop( Clip.LOOP_CONTINUOUSLY );
} else {
  clip.stop();

代码示例来源:origin: org.jvnet.hudson/netx

/**
 * Plays the clip in a continuous loop until the stop method is
 * called.
 */
public void loop() {
  if (clip == null)
    return;
  clip.loop(Clip.LOOP_CONTINUOUSLY);
}

代码示例来源:origin: stackoverflow.com

public void play(File file) throws LineUnavailableException{
 Clip clip=AudioSystem.getClip();
 clip.open(AudioSystem.getAudioInputStream(file));
 clip.loop(1);
}

代码示例来源:origin: stackoverflow.com

public void sound() {
  try{

    AudioInputStream ais = AudioSystem.getAudioInputStream(new File("./sounds/player-laser.wav"));
    Clip test = AudioSystem.getClip();  

    test.open(ais);
    test.loop(0);
  }catch(Exception ex){
    ex.printStackTrace();
  }
}

代码示例来源:origin: org.apache.ant/ant-jmf

private void playClip(Clip clip, long duration) {
  clip.loop(Clip.LOOP_CONTINUOUSLY);
  try {
    Thread.sleep(duration);
  } catch (InterruptedException e) {
    // Ignore Exception
  }
  clip.stop();
}

代码示例来源:origin: stackoverflow.com

InputStream input = getClass().getResourceAsStream("/Sound/plague.wav");
   AudioInputStream audioIn = AudioSystem.getAudioInputStream(input);
     Clip clip = AudioSystem.getClip();
     clip.open(audioIn);
     clip.loop(Clip.LOOP_CONTINUOUSLY);
   } catch (LineUnavailableException ex) {
     Logger.getLogger(knownDiseases.class.getName()).log(Level.SEVERE, null, ex);
   } catch (IOException ex) {
     Logger.getLogger(knownDiseases.class.getName()).log(Level.SEVERE, null, ex);
   } catch (UnsupportedAudioFileException ex) {
     Logger.getLogger(knownDiseases.class.getName()).log(Level.SEVERE, null, ex);
   }

代码示例来源:origin: stackoverflow.com

if(true)
{
  File file = new File("GodzillaWAV.wav");
  Clip clip = AudioSystem.getClip();
  AudioInputStream Audio = AudioSystem.getAudioInputStream(file);
  clip.open(Audio);
  clip.loop(Clip.LOOP_CONTINUOUSLY);
  Thread.sleep(6000);
}

代码示例来源:origin: playn/playn

@Override
protected boolean playImpl() {
 impl.setFramePosition(0);
 if (looping) {
  impl.loop(Clip.LOOP_CONTINUOUSLY);
 } else {
  impl.start();
 }
 return true;
}

代码示例来源:origin: com.googlecode.playn/playn-java

@Override
protected boolean playImpl() {
 impl.setFramePosition(0);
 if (looping) {
  impl.loop(Clip.LOOP_CONTINUOUSLY);
 } else {
  impl.start();
 }
 return true;
}

代码示例来源:origin: threerings/playn

@Override
protected boolean playImpl() {
 impl.setFramePosition(0);
 if (looping) {
  impl.loop(Clip.LOOP_CONTINUOUSLY);
 } else {
  impl.start();
 }
 return true;
}

代码示例来源:origin: io.playn/playn-java-base

@Override
protected boolean playImpl() {
 impl.setFramePosition(0);
 if (looping) {
  impl.loop(Clip.LOOP_CONTINUOUSLY);
 } else {
  impl.start();
 }
 return true;
}

代码示例来源:origin: stackoverflow.com

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(...);
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.start();

代码示例来源:origin: mikaelhg/openblocks

public void play() {
    if (SoundManager.isSoundEnabled()) {
      clip.setFramePosition(0);
      clip.loop(0);
    }
  }
}

代码示例来源:origin: stackoverflow.com

...
   Clip clip = (Clip) AudioSystem.getLine(info);
   clip.open(af, audio, 0, size);
   clip.loop(3); //Added this line
   clip.setLoopPoints(0, -1); //Added this line
   clip.start();
   ...

相关文章