mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
[Desktop] Map Audio Clips
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package forge.sound;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.sipgate.mp3wav.Converter;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@@ -73,7 +70,7 @@ public class AltSoundSystem extends Thread {
|
||||
|
||||
AudioInputStream audioInputStream = null;
|
||||
try {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(Converter.convertFrom(Files.asByteSource(soundFile).openStream()).toByteArray());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(AudioClip.getAudioClips(soundFile));
|
||||
audioInputStream = AudioSystem.getAudioInputStream(bis);
|
||||
} catch (UnsupportedAudioFileException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -28,7 +28,9 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -44,6 +46,14 @@ public class AudioClip implements IAudioClip {
|
||||
private String filename;
|
||||
private List<ClipWrapper> clips;
|
||||
private boolean failed;
|
||||
private static Map<String, byte[]> audioClips = new HashMap<>(30);
|
||||
|
||||
public static byte[] getAudioClips(File file) throws IOException {
|
||||
if (!audioClips.containsKey(file.toString()) ) {
|
||||
audioClips.put(file.toString(), Converter.convertFrom(Files.asByteSource(file).openStream()).toByteArray());
|
||||
}
|
||||
return audioClips.get(file.toString());
|
||||
}
|
||||
|
||||
public static boolean fileExists(String fileName) {
|
||||
File fSound = new File(ForgeConstants.SOUND_DIR, fileName);
|
||||
@@ -182,7 +192,7 @@ public class AudioClip implements IAudioClip {
|
||||
throw new IllegalArgumentException("Sound file " + fSound.toString() + " does not exist, cannot make a clip of it");
|
||||
}
|
||||
try {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(Converter.convertFrom(Files.asByteSource(fSound).openStream()).toByteArray());
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(getAudioClips(fSound));
|
||||
AudioInputStream stream = AudioSystem.getAudioInputStream(bis);
|
||||
AudioFormat format = stream.getFormat();
|
||||
DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(), ((int) stream.getFrameLength() * format.getFrameSize()));
|
||||
|
||||
Reference in New Issue
Block a user