0
那麼我做了這個聲音類與剪輯一起工作,我注意到大文件的問題。我看到人們一直在談論一個稱爲BigClip 的類,它與Clip只是能夠處理大文件相同...我在哪裏可以得到BigClip?
我的問題是我在哪裏可以得到那個類..我注意到它不符合正常java的XD 還怎麼我implent到我的代碼..
這裏是我的代碼:
package org.game.engine;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
//Declaring all the fields
public class SoundEngine {
private Clip clip;
private AudioInputStream sound;
private boolean stoped = false;
private DataLine.Info info;
private File soundFile;
//Constructor for a sound
public SoundEngine(String filename) throws Exception {
// specify the sound to play
soundFile = new File(filename);
sound = AudioSystem.getAudioInputStream(soundFile);
// load the sound into a clip
info = new DataLine.Info(Clip.class, sound.getFormat());
clip = (Clip) AudioSystem.getLine(info);
System.out.println(Integer.toString(clip.getBufferSize()));
clip.open(sound);
}
//Method do start/play the sound once
public void start() throws LineUnavailableException, IOException, UnsupportedAudioFileException{
if (stoped) {
sound = AudioSystem.getAudioInputStream(soundFile);
info = new DataLine.Info(Clip.class, sound.getFormat());
clip = (Clip) AudioSystem.getLine(info);
clip.open(sound);
stoped = false;
}
clip.start();
}
//Method do pause the sound
public void pause() {
clip.stop();
}
//Method to fully stop the sound
public void stop() {
//make sure sound reloads it self because of the full stop
stoped = true;
//closes and drains
clip.close();
clip.drain();
}
//Methd for looping sounds
public void loop() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
if (stoped) {
//reloads the sound incase the sound is fully stoped
sound = AudioSystem.getAudioInputStream(soundFile);
info = new DataLine.Info(Clip.class, sound.getFormat());
clip = (Clip) AudioSystem.getLine(info);
clip.open(sound);
stoped = false;
}
//starts the looping
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
}
在槍支和彈藥? –
因爲他開發了它,所以請問@ [Andrew Thompson](http://stackoverflow.com/users/418556/andrew-thompson) – MByD
我怎麼會讓他失望? – Amit