1
所以我被要求帮助一个Java游戏,并且我被赋予了音频角色。我得到的音频播放,但我需要它到我可以停止音频和启动一个新的音频字符串在另一个文件调用它。这就是我所拥有的;Java游戏的背景音乐
import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;
import javax.swing.*;
public class SoundTest{
// Constructor
public static void Run(String pen)throws InterruptedException {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("Test Sound");
f.setSize(300, 200);
f.setVisible(false);
try {
// Open an audio input stream.
File soundFile = new File(pen);
AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
clip.start();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
}
,我有这个调用它
import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;
import javax.swing.*;
public class SoundCall{
public static void main(String[] args)throws InterruptedException {
JFrame f = new JFrame();
SoundTest sound = new SoundTest();
sound.Run("Jskee_-_I_Am_Pharaoh_.wav");
JOptionPane.showMessageDialog(f,"Window","Cracker",JOptionPane.PLAIN_MESSAGE);
sound.stop;
sound.Run("Rejekt_-_Crank.wav");
}
}
在哪里可以实现剪辑的声明? – Jotohooh
@Jotohooh在您的SoundTest文件的顶部 – ItzBenteThePig
@Jotohooh编辑答案,让您更容易理解 – ItzBenteThePig