java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit()
// 发出当前系统歼碰带最简单的声音
tk.beep()
不需吵孝要外部包,只是用系统JDK中的 awt包下的 toolkit工具类就可以了。
String[] choics={"qq.wav",""}URL file1 = getClass().getResource(choics[0])
URL file2 = getClass().getResource(choics[1])
路径不对 或当铅棚前路径锋激蠢下银陪没有qq.wav而出错
/*** 播放音悉历乐
*
* @param mp3Path
* @param repeat
*/
public static void playSound(final String mp3Path, final int repeat) {
new Thread(new Runnable() {
@Override
public void run() {
if (mp3Path.endsWith("mp3")) {
// TODO Auto-generated method stub
MP3Player mp3 = new MP3Player(mp3Path)
int ccc = 0
while (ccc <repeat) {
try {
Thread.sleep(1000)
} catch (InterruptedException e) {
/模陆慧/ TODO Auto-generated catch block
e.printStackTrace()
}
ccc++
mp3.play()
}
} else {
try {
// .wav 文件放在java project 下面
//System.getProperty("user.dir") + File.separator+ "ring.wav"
System.out.println(mp3Path)
FileInputStream fileau = new FileInputStream(
mp3Path)
AudioStream as = new AudioStream(fileau)
int ccc = 0
while (ccc <repeat) {
try {
Thread.sleep(1000)
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
ccc++
AudioPlayer.player.start(as)
}
} catch (Exception e) {
e.printStackTrace()
}
}
}
}).start()
}
sun audio jar下载 需要自己下旦答载
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)