📄 sound.java~3~
字号:
package mymatrix;
import java.io.*;
import javax.sound.sampled.*;
public class Sound {
String m_SoundName;
Clip clip;
public Sound(String SoundName) {
jsInit();
m_SoundName=SoundName;
}
private void jsInit(){
try{
File file = new File(m_SoundName);
AudioInputStream stream = AudioSystem.getAudioInputStream(file);
AudioFormat format = stream.getFormat();
// specify what kind of line we want to create
DataLine.Info info = new DataLine.Info(Clip.class, format);
// create the line
clip = (Clip)AudioSystem.getLine(info);
// load the samples from the stream
clip.open(stream);
}
catch(Exception se){
se.printStackTrace();
}
}
public void start(){
// begin playback of the sound clip
clip.start();
}
public void stop(){
clip.stop();
}
public void loop(int LoopTime){
clip.loop(LoopTime);
}
public void pause(){
try{
clip.wait();
}
catch(Exception pe){
pe.printStackTrace();
}
}
public void continue_play(){
if(!clip.isActive())
clip.notify();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -