-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSoundLib.java
75 lines (68 loc) · 1.89 KB
/
SoundLib.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
import javax.sound.sampled.*;
import java.applet.*;
import java.util.*;
import java.io.*;
/**
* A Class to hold the sounds played in the game
*
* @author Team 3
* @version 1.0
*/
public class SoundLib
{
public static Sound background;
public static Sound button =
new Sound("resources/sounds/buttons/button1.au");
public static Sound turnPage =
new Sound("resources/sounds/buttons/Pageturn.wav");
public static Sound purchase =
new Sound("resources/sounds/buttons/purchase.wav");
public static Sound error =
new Sound("resources/sounds/buttons/error.au");
/**
* static initializer for this calss
*/
public static void SoundLib() {
//grab filepath of soundtrack
String filePath =
"resources/sounds/backgroundSounds/tryEverything.au";
// plays random background sound from filePath
background = new Sound(filePath);
// plays audio on loop
background.playLoop();
}
//static sub class for holding single audio files
static class Sound{
private AudioClip sound; // Sound player
/**
* Constructor for sound
*
* @param filename The path of the sound file
*/
Sound(String filename) {
try {
sound = Applet.newAudioClip(
this.getClass().getResource(filename)); // Load the Sound
} catch (Exception e) {
} // Satisfy the catch
}
/**
* Play sound on a loop
*/
public void playLoop() {
sound.loop(); // Play
}
/**
* stop sound
*/
public void stop() {
sound.stop(); // Play
}
/**
* play sound once
*/
public void play() {
sound.play(); // Play only once
}
}
}