-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgm_se.java
89 lines (80 loc) · 3.23 KB
/
bgm_se.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import javax.sound.sampled.*;
import javax.sound.sampled.AudioFileFormat.Type;
import javax.sound.sampled.AudioFormat;
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;
/* View : BGM, SE */
class Bgm_se {
Clip clip;
public Bgm_se(String str) {
if (str.equals("Sword")) {
clip = createClip(new File("bgm/sword.wav"));
} else if (str.equals("Hammer")) {
clip = createClip(new File("bgm/hammer.wav"));
} else if (str.equals("DeathEnemy")) {
clip = createClip(new File("bgm/syoumetu.wav"));
} else if (str.equals("Game")) {
clip = createClip(new File("bgm/dangeon01.wav"));
} else if (str.equals("GameOver")) {
clip = createClip(new File("bgm/dead-sound.wav"));
} else if (str.equals("Start")) {
clip = createClip(new File("bgm/start1.wav"));
} else if (str.equals("Result")) {
clip = createClip(new File("bgm/gameclear.wav"));
} else if (str.equals("Book")) {
clip = createClip(new File("bgm/book_se.wav"));
} else if (str.equals("getItem")) {
clip = createClip(new File("bgm/soubi-01.wav"));
} else if (str.equals("Coin")) {
clip = createClip(new File("bgm/coin.wav"));
} else if (str.equals("Star")) {
clip = createClip(new File("bgm/makestar3.wav"));
} else if (str.equals("Trap")) {
clip = createClip(new File("bgm/Trap.wav"));
} else if (str.equals("Gacha")) {
clip = createClip(new File("bgm/gacha.wav"));
} else if (str.equals("Lunatic")) {
clip = createClip(new File("bgm/lunatic.wav"));
} else if (str.equals("Button")) {
clip = createClip(new File("bgm/button.wav"));
}
}
public static Clip createClip(File path) {
try (AudioInputStream ais = AudioSystem.getAudioInputStream(path)) {
AudioFormat af = ais.getFormat();
DataLine.Info dataLine = new DataLine.Info(Clip.class, af);
Clip c = (Clip) AudioSystem.getLine(dataLine);
c.open(ais);
FloatControl volume = (FloatControl) c.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(-30.0f); // ここで音量を調整(引数はデシベル)
return c;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
return null;
}
public void play() {
clip.setFramePosition(0);
clip.loop(0);
clip.start();
}
public void loop() {
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
public void stop() {
clip.stop();
}
}