[英]Stop previously played WAV sound
I am making a desktop Softphone-like application in Java. 我正在用Java开发类似于Softphone的桌面应用程序。 I want to add the dialed-number sounds (DTMF).
我想添加拨号号码的声音(DTMF)。 For example, when I dial 51, it plays
dtmf5.wav
after pressing the 5, but then it plays dtmf1.wav
when I press the 1, without stopping the 5's tone. 例如,当我拨51,它起着
dtmf5.wav
按5之后,但随后它起着dtmf1.wav
当我按下1,不停止5的基调。 How do I make sure only one sound - the latest one - plays at once? 如何确保只播放一种声音(最新的声音)一次?
This is what I'm using to play the sound: 这是我用来播放声音的内容:
private void lbl01MouseReleased(java.awt.event.MouseEvent evt) {
String val=txtdisplay.getText() + "1";
txtdisplay.setText(val);
if (evt.getSource() == lbl01) {
URL urlClick = StartGUI.class.getResource("/Dtmf/dtmf1.wav");
AudioClip click = Applet.newAudioClip(urlClick);
click.play();
}
}
To stop any previously playing audio, you can keep a reference to the AudioClip
when it is created. 要停止以前播放的音频,可以在创建音频
AudioClip
保留对其的引用。 When the action is sent to play a Clip just stop the previous clip by calling it's stop
method. 发送动作以播放剪辑后,只需调用其
stop
方法即可停止上一个剪辑。
AudioClip currentAudio = null;
...
private void lbl01MouseReleased(java.awt.event.MouseEvent evt){
String val=txtdisplay.getText() +"1";
txtdisplay.setText(val);
if ( currentAudio != null ){
currentAudio.stop();
}
if (evt.getSource() == lbl01)
{
URL urlClick = StartGUI.class.getResource("/Dtmf/dtmf1.wav");
currentAudio = Applet.newAudioClip(urlClick);
currentAudio.play();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.