sound.java~3~
来自「JBuilder实现的具有单机」· JAVA~3~ 代码 · 共 62 行
JAVA~3~
62 行
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 + =
减小字号Ctrl + -
显示快捷键?