Skip to content

Commit b958392

Browse files
committed
Updated music
now music can be played when built
1 parent aeb119d commit b958392

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.redomar.game.lib;
22

33
import java.io.BufferedInputStream;
4-
import java.io.FileInputStream;
5-
import java.net.URL;
4+
import java.io.InputStream;
65

76
import com.redomar.game.Game;
87

98
import javazoom.jl.player.Player;
109

1110
public class Music implements Runnable{
1211

13-
private String file;
12+
private InputStream file;
1413
private Player musicPlayer;
1514

16-
public Music(URL url){
17-
this.file = url.toString().substring(6);
15+
public Music(InputStream url){
16+
this.file = url;
1817
}
1918

2019
public Music() {
@@ -23,8 +22,7 @@ public Music() {
2322

2423
public void Play(){
2524
try {
26-
FileInputStream inputFile = new FileInputStream(file);
27-
BufferedInputStream buffered = new BufferedInputStream(inputFile);
25+
BufferedInputStream buffered = new BufferedInputStream(file);
2826
musicPlayer = new Player(buffered);
2927
musicPlayer.play();
3028
} catch (Exception e) {
@@ -35,7 +33,18 @@ public void Play(){
3533

3634
@Override
3735
public void run() {
38-
Music music = new Music(Game.class.getResource("/music/yoshi.mp3"));
39-
music.Play();
36+
Music music = new Music(Game.class.getResourceAsStream("/music/yoshi.mp3"));
37+
while(true){
38+
music.Play();
39+
}
40+
}
41+
42+
public void stop() {
43+
Music music = new Music(Game.class.getResourceAsStream("/music/yoshi.mp3"));
44+
while(true){
45+
music.stop();
46+
}
4047
}
48+
49+
4150
}

0 commit comments

Comments
 (0)