Task 1
This commit is contained in:
parent
47a4af1cc0
commit
12d4bb3c4d
@ -0,0 +1,6 @@
|
|||||||
|
package fr.enssat.BoulderDash.bridges;
|
||||||
|
|
||||||
|
public interface SoundBridge {
|
||||||
|
void play();
|
||||||
|
void stop();
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package fr.enssat.BoulderDash.bridges;
|
||||||
|
|
||||||
|
public class SoundBridgeFactory {
|
||||||
|
public static SoundBridge createSoundBridgeFromFilePath(String filePath) {
|
||||||
|
return new SoundJLayerBridge(filePath);
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ import javazoom.jl.player.FactoryRegistry;
|
|||||||
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
* @author Valerian Saliou <valerian@valeriansaliou.name>
|
||||||
* @since 2015-06-19
|
* @since 2015-06-19
|
||||||
*/
|
*/
|
||||||
public class SoundJLayerBridge extends PlaybackListener implements Runnable {
|
public class SoundJLayerBridge extends PlaybackListener implements Runnable, SoundBridge {
|
||||||
private String filePath;
|
private String filePath;
|
||||||
private AdvancedPlayer player;
|
private AdvancedPlayer player;
|
||||||
private Thread playerThread;
|
private Thread playerThread;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.enssat.BoulderDash.helpers;
|
package fr.enssat.BoulderDash.helpers;
|
||||||
|
|
||||||
import fr.enssat.BoulderDash.bridges.SoundJLayerBridge;
|
import fr.enssat.BoulderDash.bridges.SoundBridge;
|
||||||
|
import fr.enssat.BoulderDash.bridges.SoundBridgeFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@ -17,8 +18,8 @@ import java.util.HashMap;
|
|||||||
public class AudioLoadHelper {
|
public class AudioLoadHelper {
|
||||||
private static String pathToAudioStore = "./res/audio";
|
private static String pathToAudioStore = "./res/audio";
|
||||||
|
|
||||||
private SoundJLayerBridge musicToPlay;
|
private SoundBridge musicToPlay;
|
||||||
private HashMap<String, SoundJLayerBridge> preloadedSounds;
|
private HashMap<String, SoundBridge> preloadedSounds;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
@ -47,9 +48,8 @@ public class AudioLoadHelper {
|
|||||||
this.stopMusic();
|
this.stopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.musicToPlay = new SoundJLayerBridge(
|
String filePath = this.getMusicPathInAudioStore(musicId);
|
||||||
this.getMusicPathInAudioStore(musicId)
|
this.musicToPlay = SoundBridgeFactory.createSoundBridgeFromFilePath(filePath);
|
||||||
);
|
|
||||||
this.musicToPlay.play();
|
this.musicToPlay.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ public class AudioLoadHelper {
|
|||||||
private void preloadSounds() {
|
private void preloadSounds() {
|
||||||
// Initialize
|
// Initialize
|
||||||
String curSoundIdPrep;
|
String curSoundIdPrep;
|
||||||
this.preloadedSounds = new HashMap<String, SoundJLayerBridge>();
|
this.preloadedSounds = new HashMap<>();
|
||||||
|
|
||||||
// List sound files
|
// List sound files
|
||||||
File soundsDir = new File(AudioLoadHelper.pathToAudioStore + "/sounds/");
|
File soundsDir = new File(AudioLoadHelper.pathToAudioStore + "/sounds/");
|
||||||
@ -82,9 +82,8 @@ public class AudioLoadHelper {
|
|||||||
curSoundIdPrep = curSoundId.getName();
|
curSoundIdPrep = curSoundId.getName();
|
||||||
curSoundIdPrep = curSoundIdPrep.substring(0, curSoundIdPrep.lastIndexOf('.'));
|
curSoundIdPrep = curSoundIdPrep.substring(0, curSoundIdPrep.lastIndexOf('.'));
|
||||||
|
|
||||||
this.preloadedSounds.put(curSoundIdPrep, new SoundJLayerBridge(
|
this.preloadedSounds.put(curSoundIdPrep,
|
||||||
curSoundId.getPath()
|
SoundBridgeFactory.createSoundBridgeFromFilePath(curSoundId.getPath()));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +93,7 @@ public class AudioLoadHelper {
|
|||||||
* @param soundId Sound identifier
|
* @param soundId Sound identifier
|
||||||
* @return Preloaded sound instance
|
* @return Preloaded sound instance
|
||||||
*/
|
*/
|
||||||
private SoundJLayerBridge getPreloadedSound(String soundId) {
|
private SoundBridge getPreloadedSound(String soundId) {
|
||||||
return this.preloadedSounds.get(soundId);
|
return this.preloadedSounds.get(soundId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user