This commit is contained in:
0nlineSam 2025-01-23 13:26:59 +01:00
parent 47a4af1cc0
commit 12d4bb3c4d
4 changed files with 24 additions and 12 deletions

View File

@ -0,0 +1,6 @@
package fr.enssat.BoulderDash.bridges;
public interface SoundBridge {
void play();
void stop();
}

View File

@ -0,0 +1,7 @@
package fr.enssat.BoulderDash.bridges;
public class SoundBridgeFactory {
public static SoundBridge createSoundBridgeFromFilePath(String filePath) {
return new SoundJLayerBridge(filePath);
}
}

View File

@ -14,7 +14,7 @@ import javazoom.jl.player.FactoryRegistry;
* @author Valerian Saliou <valerian@valeriansaliou.name>
* @since 2015-06-19
*/
public class SoundJLayerBridge extends PlaybackListener implements Runnable {
public class SoundJLayerBridge extends PlaybackListener implements Runnable, SoundBridge {
private String filePath;
private AdvancedPlayer player;
private Thread playerThread;

View File

@ -1,6 +1,7 @@
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.FilenameFilter;
@ -17,8 +18,8 @@ import java.util.HashMap;
public class AudioLoadHelper {
private static String pathToAudioStore = "./res/audio";
private SoundJLayerBridge musicToPlay;
private HashMap<String, SoundJLayerBridge> preloadedSounds;
private SoundBridge musicToPlay;
private HashMap<String, SoundBridge> preloadedSounds;
/**
* Class constructor
@ -47,9 +48,8 @@ public class AudioLoadHelper {
this.stopMusic();
}
this.musicToPlay = new SoundJLayerBridge(
this.getMusicPathInAudioStore(musicId)
);
String filePath = this.getMusicPathInAudioStore(musicId);
this.musicToPlay = SoundBridgeFactory.createSoundBridgeFromFilePath(filePath);
this.musicToPlay.play();
}
@ -66,7 +66,7 @@ public class AudioLoadHelper {
private void preloadSounds() {
// Initialize
String curSoundIdPrep;
this.preloadedSounds = new HashMap<String, SoundJLayerBridge>();
this.preloadedSounds = new HashMap<>();
// List sound files
File soundsDir = new File(AudioLoadHelper.pathToAudioStore + "/sounds/");
@ -82,9 +82,8 @@ public class AudioLoadHelper {
curSoundIdPrep = curSoundId.getName();
curSoundIdPrep = curSoundIdPrep.substring(0, curSoundIdPrep.lastIndexOf('.'));
this.preloadedSounds.put(curSoundIdPrep, new SoundJLayerBridge(
curSoundId.getPath()
));
this.preloadedSounds.put(curSoundIdPrep,
SoundBridgeFactory.createSoundBridgeFromFilePath(curSoundId.getPath()));
}
}
@ -94,7 +93,7 @@ public class AudioLoadHelper {
* @param soundId Sound identifier
* @return Preloaded sound instance
*/
private SoundJLayerBridge getPreloadedSound(String soundId) {
private SoundBridge getPreloadedSound(String soundId) {
return this.preloadedSounds.get(soundId);
}