-
Notifications
You must be signed in to change notification settings - Fork 6
/
AudioPlayer.java
56 lines (51 loc) · 1.41 KB
/
AudioPlayer.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
import greenfoot.GreenfootSound;
/**
* Write a description of class AudioPlayer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class AudioPlayer
{
// instance variables - replace the example below with your own
/**
* Constructor for objects of class AudioPlayer
*/
public AudioPlayer()
{
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public static void play(String... audio)
{
int index = (int)(Math.random()*audio.length);
GreenfootSound temp = new GreenfootSound(audio[index]);
temp.play();
}
public static void play(int volume,String... audio)
{
int index = (int)(Math.random()*audio.length);
GreenfootSound temp = new GreenfootSound(audio[index]);
temp.setVolume(volume);
temp.play();
}
public static void play(boolean loop, String... audio)
{
int index = (int)(Math.random()*audio.length);
GreenfootSound temp = new GreenfootSound(audio[index]);
if (loop) {
temp.playLoop();
} else {
temp.play();
}
}
public static void stop(GreenfootSound... audio) {
for (int i = 0; i < audio.length; i++) {
audio[i].stop();
}
}
}