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

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

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

Clip.open介绍

暂无

代码示例

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

public static synchronized void playSound(final String url) {
 new Thread(new Runnable() {
 // The wrapper thread is unnecessary, unless it blocks on the
 // Clip finishing; see comments.
  public void run() {
   try {
    Clip clip = AudioSystem.getClip();
    AudioInputStream inputStream = AudioSystem.getAudioInputStream(
     Main.class.getResourceAsStream("/path/to/sounds/" + url));
    clip.open(inputStream);
    clip.start(); 
   } catch (Exception e) {
    System.err.println(e.getMessage());
   }
  }
 }).start();
}

代码示例来源:origin: RipMeApp/ripme

/**
 * Plays a sound from a file.
 *
 * @param filename Path to the sound file
 */
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(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);
  }
}

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

AudioInputStream audioIn = AudioSystem.getAudioInputStream(MyClazz.class.getResource("music.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
clip.start();

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

public static void play(String filename)
{
  try
  {
    Clip clip = AudioSystem.getClip();
    clip.open(AudioSystem.getAudioInputStream(new File(filename)));
    clip.start();
  }
  catch (Exception exc)
  {
    exc.printStackTrace(System.out);
  }
}

代码示例来源: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

public static void playSound(File soundfile)  throws LineUnavailableException, UnsupportedAudioFileException, IOException{
    AudioInputStream audioInputStream = null;
    audioInputStream = AudioSystem.getAudioInputStream(soundfile);              
    Clip clip = AudioSystem.getClip();              
    clip.open(audioInputStream);
    clip.start();
}

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

AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);              
  // Get a sound clip resource.
  Clip clip = AudioSystem.getClip();
  // Open audio clip and load samples from the audio input stream.
  clip.open(audioIn);
  clip.start();

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

AudioInputStream audioIn = AudioSystem.getAudioInputStream(
  new ByteArrayInputStream(decoded));
Clip song = AudioSystem.getClip();
song.open(audioIn);
song.start();

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

//initialize this at the beginning of your program
AudioInputStream soundStream = AudioSystem.getAudioInputStream(new File("sound.wav"));

Clip soundEffect = AudioSystem.getClip();
soundEffect.open(soundStream);

...

//later, play the sound
soundEffect.start();

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

URL url2 = new URL("http://www.villagegeek.com/downloads/webwavs/Austin_Powers_death.wav");
Clip clip2 = AudioSystem.getClip();
AudioInputStream ais2 = AudioSystem.getAudioInputStream(url2);
clip2.open(ais2);
clip2.start();

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

String soundName = "yourSound.wav";    
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(soundName).getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();

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

try {
  File file = new File(src); // src is the location of the file
  AudioInputStream stream = AudioSystem.getAudioInputStream(file);
  Clip clip = AudioSystem.getClip();
  clip.open(stream);
  clip.start();
} catch (Exception e) {
  e.printStackTrace();
}

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

InputStream inaudio = getClass().getResourceAsStream("/audio/retrolevel.wav");
Clip clip = null;
try {
  clip = AudioSystem.getClip();
  clip.open(AudioSystem.getAudioInputStream(inaudio));
} catch (IOException | LineUnavailableException | UnsupportedAudioFileException e1) {
  e1.printStackTrace();
}
clip.start();

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

try{
  AudioInputStream audioInputStream =AudioSystem.getAudioInputStream(this.getClass().getResource("kp.mp3"));
  Clip clip = AudioSystem.getClip();
  clip.open(audioInputStream);
  clip.start( );
}
catch(Exception ex)
{  }

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

public void play(Film song) {
  try {
    Clip sound = AudioSystem.getClip();

    sound.open(AudioSystem.getAudioInputStream(new File(song.getClip())));

    sound.start();

  } catch (Exception e) {
    System.out.println("Whatever" + e);
  }
 }
}

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

try
{
   Clip clickClip = AudioSystem.getClip();
   URL clipURL = new URL("file://C:/aFile.wav");
   AudioInputStream ais = AudioSystem.getAudioInputStream(clipURL);
   clickClip.open(ais);
   clickClip.start();
}
catch(Exception e)
{
   System.out.ptintln("Something didn't work !\n" + e.printStackTrace());
}

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

AudioInputStream inputStream = AudioSystem.getAudioInputStream(ClientMain.class.getResourceAsStream("sounds/" + url));
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip)AudioSystem.getLine(info);
clip.open(inputStream);
clip.start();

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

AudioInputStream stream = 
  AudioSystem.getAudioInputStream(getClass().getResource("/sounds/button.wav"));
Clip clip = AudioSystem.getClip();
clip.open(stream);
clip.start();

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

void playSound(String soundFile) {
  File f = new File("./" + soundFile);
  audioIn = AudioSystem.getAudioInputStream(f.toURI().toURL());  
  Clip clip = AudioSystem.getClip();
  clip.open(audioIn);
  clip.start();
}

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

public void playSound() {
 try {
    AudioStream as = AudioSystem.getAudioInputStream(this.getClass().getResource("resources\\beep-2.wav"));
    Clip clip = AudioSystem.getClip();
    clip.open(as);
    clip.start( );
   }
 catch (Exception e) {
 e.printStackTrace();
 }
 }

相关文章