This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBGM.java
71 lines (67 loc) · 1.61 KB
/
BGM.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
/**
* The splash screen
*
* Last edit: 6/18/2020
* @author Eric
* @version 1.1
* @since 1.0
*/
import java.io.*;
import javax.sound.sampled.*;
public class BGM {
private Clip clip;
private AudioInputStream audioInputStream;
private Long currentFrame;
private String name;
/**
* Constructor
*/
public BGM(String name) {
this.name = name;
try {
audioInputStream = AudioSystem.getAudioInputStream(this.getClass().getResource(Utility.RES_NAME + "/bgm/"+name+".wav"));
clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
} catch(Exception e) {}
}
/**
* Play method
*/
public void play() {
try {
clip.start();
} catch (Exception e) {}
}
/**
* Pause Method
*/
public void pause() {
try {
this.currentFrame = this.clip.getMicrosecondPosition();
clip.stop();
} catch (Exception e) {}
}
/**
* Resume Method
*/
public void resume() {
try {
clip.close();
audioInputStream = AudioSystem.getAudioInputStream(this.getClass().getResource(Utility.RES_NAME + "/bgm/"+name+".wav"));
clip.open(audioInputStream);
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.setMicrosecondPosition(currentFrame);
clip.start();
} catch(Exception e) {}
}
/**
* Stop method
*/
public void stop() {
try {
clip.stop();
clip.close();
} catch(Exception e) {}
}
}