本文整理汇总了Java中javax.sound.sampled.AudioSystem.getClip方法的典型用法代码示例。如果您正苦于以下问题:Java AudioSystem.getClip方法的具体用法?Java AudioSystem.getClip怎么用?Java AudioSystem.getClip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.AudioSystem
的用法示例。
在下文中一共展示了AudioSystem.getClip方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EZSound
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Creates a new sound out of the given file. Must be a .wav file.
*
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addSound() method which will perform additional background actions to bind the sound to the window.
*
* @param file of the sound to load.
* */
public EZSound(String file) {
/*
filename = file;
sound = tryLoadSound(file);
if (sound == null) {
System.out.println("Error loading sound file");
System.exit(1);
}
if (sound == null) {
reloadClip();
}
*/
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(file).getAbsoluteFile());
sound = AudioSystem.getClip();
sound.open(ais);
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Error loading sound file, it may not exist or another program has a lock on it.");
System.exit(1);
}
}
示例2: run
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* The sound is load and play in a thread no slow down the engine.
* */
@Override
public void run() {
try {
InputStream in = new BufferedInputStream(this.getClass().getResourceAsStream(this.filename + ".wav"));
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(in));
if (this.loop){
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
clip.start();
}catch (Exception e){
System.err.println(e);
}
}
示例3: loadClip
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void loadClip() {
try {
clip = AudioSystem.getClip();
InputStream in = getClass().getClassLoader().getResourceAsStream(filePath);
BufferedInputStream bufferedIn = new BufferedInputStream(in);
AudioInputStream audioIn = AudioSystem.getAudioInputStream(bufferedIn);
clip.open(audioIn);
volume = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
} catch (LineUnavailableException | UnsupportedAudioFileException | IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
示例4: playSound
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private synchronized void playSound(final String audioFileName) {
if(isSoundEnabled) {
try {
Clip clip = AudioSystem.getClip();
InputStream inputStream = MainWindow.class.getResourceAsStream(audioFileName);
if(inputStream != null) {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
clip.open(audioInputStream);
clip.start();
}
else {
System.out.println("Input stream not valid");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
示例5: open
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
@Override
public void open() throws AudioException {
try {
this.audioInputStream = Audio.getAudioInputStream(this.resource);
this.clip = AudioSystem.getClip();
this.clip.open(this.audioInputStream);
this.clip.addLineListener(event -> {
if(event.getType().equals(LineEvent.Type.STOP) && this.clip.getMicrosecondPosition() >= this.clip.getMicrosecondLength()) {
this.trigger(AudioEvent.Type.REACHED_END);
}
});
this.controls = AbstractAudio.extractControls(this.clip, this.controls);
this.open = true;
this.trigger(AudioEvent.Type.OPENED);
} catch(Exception exception) {
throw new AudioException(exception);
}
}
示例6: loadSound
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* WAV files only
*
* @param name
* Name to store sound as
* @param file
* Sound file
*/
public static void loadSound(String name, String file) {
try {
System.out.print("Loading sound file: \"" + file + "\" into clip: \"" + name + "\", ");
BufferedInputStream in = new BufferedInputStream(SoundPlayer.class.getResourceAsStream(file));
AudioInputStream ain = AudioSystem.getAudioInputStream(in);
Clip c = AudioSystem.getClip();
c.open(ain);
c.setLoopPoints(0, -1);
clips.put(name, c);
ain.close();
in.close();
System.out.println("Done.");
} catch (Exception e) {
System.out.println("Failed. (" + e.getMessage() + ")");
}
}
示例7: SoundPlayingThread
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public SoundPlayingThread(ListedSong listedSong, ProgressBar progress) {
this.listedSong = listedSong;
this.audioFile = listedSong.file;
this.progress = progress;
if (audioFile != null) {
try {
AudioInputStream audioInputStream;
if(audioFile.getName().endsWith(".ogg") || audioFile.getName().endsWith(".mp3")) {
audioInputStream = createFromOgg(audioFile);
}
else { // wav
audioInputStream = AudioSystem.getAudioInputStream(audioFile);
}
clip = AudioSystem.getClip();
clip.open(audioInputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例8: playAudio
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public void playAudio(int tempo, boolean flag) throws UnsupportedAudioFileException, LineUnavailableException, IOException, InterruptedException{
Clip clip = AudioSystem.getClip();
URL url = getClass().getResource("/audio/smb_die.wav");
URL urlToHot = this.getClass().getResource("/audio/smb_die.wav");
System.out.println(urlToHot);
this.audio = Applet.newAudioClip(url);
if(flag) audio.loop();
else audio.stop();
}
示例9: playSound
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
/**
* Plays a sound
* @param soundFile The sound in the form of a File
*/
public static void playSound(File soundFile)
{
Clip clip;
try
{
clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(soundFile));
clip.start();
}
catch (Exception e) {}
}
示例10: Sound
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public Sound(String file){
try {
ais = AudioSystem.getAudioInputStream(new File(file));
clip = AudioSystem.getClip();
clip.open(ais);
} catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) {
e.printStackTrace();
}
}
示例11: load
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public static void load(String s, String n) {
if(clips.get(n) != null) return;
Clip clip;
try {
AudioInputStream ais =
AudioSystem.getAudioInputStream(
JukeBox.class.getResourceAsStream(s)
);
AudioFormat baseFormat = ais.getFormat();
AudioFormat decodeFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false
);
AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);
clip = AudioSystem.getClip();
clip.open(dais);
clips.put(n, clip);
}
catch(Exception e) {
e.printStackTrace();
}
}
示例12: loadClip
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void loadClip(File audioFile) {
try {
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
clip = AudioSystem.getClip();
clip.open(audioStream);
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: SFXClip
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
public SFXClip(String fileName)
{
File file = new File(fileName);
try
{
AudioInputStream stream = AudioSystem.getAudioInputStream(file);
this.clip = AudioSystem.getClip();
this.clip.open(stream);
}
catch(Exception e)
{
e.printStackTrace();
}
}
示例14: jButton16ActionPerformed
import javax.sound.sampled.AudioSystem; //导入方法依赖的package包/类
private void jButton16ActionPerformed(
java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
System.out.print("\7"); //Вот это вот издает звук
Clip clip = null;
try {
clip = AudioSystem.getClip();
} catch (LineUnavailableException ex) {
ex.printStackTrace();
}
byte[] buf = new byte[1024];
for (int j = 0; j < buf.length; j++) {
buf[j] = (byte) j;
}
AudioFormat af = new AudioFormat(
11025f,
8, // sample size in bits
2, // channels
true, // signed
false // bigendian
);
try {
byte[] b = buf;
AudioInputStream ais = new AudioInputStream(new ByteArrayInputStream(b), af, 512);
clip.open(ais);
} catch (Exception e) {
e.printStackTrace();
}
}