一次播放多个声音Java [英] Playing Multiple Sounds at once Java
本文介绍了一次播放多个声音Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试在Java中一次播放多种声音,一次播放1种声音没有问题,但是如果我尝试一次播放3种声音,那只会播放1个声音(我希望这是有道理的)
I've been trying to play multiple sounds at once within Java for a little bit now, I have no problem with playing 1 sound at a single time, but if I try to play like 3 at a time, it will only play 1 sound (I hope this makes sense)
这是我的代码:
public static void play(String file) {
try {
clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(new File(file)));
clip.start();
while (!clip.isRunning())
Thread.sleep(10);
while (clip.isRunning())
Thread.sleep(10);
clip.close();
} catch (Exception e) {
e.printStackTrace();
}
}
我如何使用此方法的示例:
An example of how I use this method:
AudioPlayer.play("sound1.wav");
当我也想这样做时
AudioPlayer.play("sound1.wav");
AudioPlayer.play("sound2.wav");
AudioPlayer.play("sound3.wav");
同样,这并不重要,但是也可以做这样的事情:
Also, not important but it would also be nice to do something like this as well:
AudioPlayer.getPlayingSound("sound1.wav").setVolume(-0.85f);
推荐答案
您可能会尝试使用多线程技术来同时播放多种声音.
You might try to use multithreading to play multiple sounds at same time.
这篇关于一次播放多个声音Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文