Skip to content

Commit aeb119d

Browse files
committed
Added music
only works in the IDE
1 parent 486e10d commit aeb119d

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

res/music/jl1.0.1.jar

103 KB
Binary file not shown.

res/music/yoshi.mp3

1.8 MB
Binary file not shown.

src/com/redomar/game/Game.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.redomar.game.gfx.Screen;
1818
import com.redomar.game.gfx.SpriteSheet;
1919
import com.redomar.game.level.LevelHandler;
20+
import com.redomar.game.lib.Music;
2021
import com.redomar.game.net.GameClient;
2122
import com.redomar.game.net.GameServer;
2223
import com.redomar.game.net.packets.Packet00Login;
@@ -108,6 +109,9 @@ public synchronized void start() {
108109
running = true;
109110
new Thread(this).start();
110111

112+
Music music = new Music();
113+
new Thread(music).start();
114+
111115
if (Jdata_Host == 0) {
112116
socketServer = new GameServer(this);
113117
socketServer.start();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.redomar.game.lib;
2+
3+
import java.io.BufferedInputStream;
4+
import java.io.FileInputStream;
5+
import java.net.URL;
6+
7+
import com.redomar.game.Game;
8+
9+
import javazoom.jl.player.Player;
10+
11+
public class Music implements Runnable{
12+
13+
private String file;
14+
private Player musicPlayer;
15+
16+
public Music(URL url){
17+
this.file = url.toString().substring(6);
18+
}
19+
20+
public Music() {
21+
22+
}
23+
24+
public void Play(){
25+
try {
26+
FileInputStream inputFile = new FileInputStream(file);
27+
BufferedInputStream buffered = new BufferedInputStream(inputFile);
28+
musicPlayer = new Player(buffered);
29+
musicPlayer.play();
30+
} catch (Exception e) {
31+
System.out.println("Problem playing file " + file);
32+
System.out.println(e);
33+
}
34+
}
35+
36+
@Override
37+
public void run() {
38+
Music music = new Music(Game.class.getResource("/music/yoshi.mp3"));
39+
music.Play();
40+
}
41+
}

0 commit comments

Comments
 (0)