File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed
Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change 11package com .redomar .game .lib ;
22
33import java .io .BufferedInputStream ;
4- import java .io .FileInputStream ;
5- import java .net .URL ;
4+ import java .io .InputStream ;
65
76import com .redomar .game .Game ;
87
98import javazoom .jl .player .Player ;
109
1110public 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}
You can’t perform that action at this time.
0 commit comments