replaced Exception with specific subclass
parent
8d32fde337
commit
fa59f027ec
|
@ -1,10 +1,9 @@
|
|||
package magic.data;
|
||||
|
||||
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.*;
|
||||
|
||||
import magic.MagicMain;
|
||||
import magic.model.MagicGame;
|
||||
|
@ -20,26 +19,32 @@ public class SoundEffects {
|
|||
private static final File SOUNDS_PATH=new File(MagicMain.getGamePath(),"sounds");
|
||||
private static final SoundEffects INSTANCE=new SoundEffects();
|
||||
|
||||
private SoundEffects() {
|
||||
|
||||
}
|
||||
private SoundEffects() {}
|
||||
|
||||
public void playClip(final String name) {
|
||||
if (GeneralConfig.getInstance().isSound()) {
|
||||
AudioInputStream inputStream = null;
|
||||
try {
|
||||
final Clip clip=AudioSystem.getClip();
|
||||
final AudioInputStream inputStream=AudioSystem.getAudioInputStream(new File(SOUNDS_PATH,name));
|
||||
final Clip clip = AudioSystem.getClip();
|
||||
inputStream = AudioSystem.getAudioInputStream(new File(SOUNDS_PATH,name));
|
||||
clip.open(inputStream);
|
||||
inputStream.close();
|
||||
clip.start();
|
||||
} catch (final Exception ex) {
|
||||
} catch (final LineUnavailableException ex) {
|
||||
System.err.println("WARNING. Unable to load clip " + name);
|
||||
System.err.println(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
} catch (final UnsupportedAudioFileException ex) {
|
||||
System.err.println("WARNING. Unable to load clip " + name);
|
||||
} catch (final IOException ex) {
|
||||
System.err.println("WARNING. Unable to load clip " + name);
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null) inputStream.close();
|
||||
} catch (final IOException ex) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void playClip(final MagicGame game,final String name) {
|
||||
if (game.isSound()) {
|
||||
playClip(name);
|
||||
|
|
Loading…
Reference in New Issue