[英]playing a sound
I'm very beginner in Java, so ... 我是Java的初学者,所以...
I've written a simple Java code to display images from my hard drive wherever I click the mouse, not on the applet, on panel, now how can I make a sound play automatically when I view 6 pictures ? 我已经编写了一个简单的Java代码,可以在单击鼠标的任何地方(而不是在小程序上)在面板上显示硬盘中的图像,现在,当我查看6张图片时如何自动播放声音?
public void mouseClicked(MouseEvent e) {
if (count == images.length - 1) {
???????????????????????
} else {
count++;
}
x = e.getX();
y = e.getY();
frameTest.repaint();
}
I want to play a sound file from the Hard drive, in the place of question marks .. 我想从硬盘播放声音文件,而不是问号..
can some one help plz ? 有人可以帮忙吗?
Try to write this inside your if : 尝试在您的if中写这个:
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());
}
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.