mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added linelistener to SoundEffectAsset
This commit is contained in:
@@ -5,8 +5,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.toop.framework.dispatch.interfaces.Dispatcher;
|
||||
import org.toop.framework.dispatch.JavaFXDispatcher;
|
||||
import org.toop.annotations.TestsOnly;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
import org.toop.framework.resource.resources.BaseResource;
|
||||
import org.toop.framework.resource.types.AudioResource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package org.toop.framework.resource.resources;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import javax.sound.sampled.*;
|
||||
|
||||
import org.toop.framework.resource.types.AudioResource;
|
||||
import org.toop.framework.resource.types.FileExtension;
|
||||
import org.toop.framework.resource.types.LoadableResource;
|
||||
|
||||
import static javax.sound.sampled.LineEvent.Type.CLOSE;
|
||||
import static javax.sound.sampled.LineEvent.Type.STOP;
|
||||
|
||||
@FileExtension({"wav"})
|
||||
public class SoundEffectAsset extends BaseResource implements LoadableResource, AudioResource {
|
||||
private final Clip clip = AudioSystem.getClip();
|
||||
|
||||
private LineListener onEnd = null;
|
||||
private LineListener onError = null;
|
||||
|
||||
private double volume = 100; // TODO: Find a better way to set volume on clip load
|
||||
|
||||
public SoundEffectAsset(final File audioFile) throws LineUnavailableException {
|
||||
@@ -71,6 +70,12 @@ public class SoundEffectAsset extends BaseResource implements LoadableResource,
|
||||
|
||||
clip.close(); // Releases native resources (empties buffer)
|
||||
|
||||
this.getClip().removeLineListener(this.onEnd);
|
||||
this.getClip().removeLineListener(this.onError);
|
||||
|
||||
this.onEnd = null;
|
||||
this.onError = null;
|
||||
|
||||
this.isLoaded = false;
|
||||
}
|
||||
|
||||
@@ -105,12 +110,25 @@ public class SoundEffectAsset extends BaseResource implements LoadableResource,
|
||||
|
||||
@Override
|
||||
public void setOnEnd(Runnable run) {
|
||||
// TODO
|
||||
this.onEnd = event -> {
|
||||
if (event.getType() == LineEvent.Type.STOP) {
|
||||
run.run();
|
||||
}
|
||||
};
|
||||
|
||||
this.getClip().addLineListener(this.onEnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnError(Runnable run) {
|
||||
// TODO
|
||||
// this.onError = event -> {
|
||||
// if (event.getType() == LineEvent.Type.STOP) {
|
||||
// run.run();
|
||||
// }
|
||||
// }; TODO
|
||||
//
|
||||
// this.getClip().addLineListener(this.onEnd);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.toop.framework.resource.types;
|
||||
public interface AudioResource {
|
||||
String getName();
|
||||
void updateVolume(double volume);
|
||||
// boolean isPlaying();
|
||||
void play();
|
||||
void stop();
|
||||
void setOnEnd(Runnable run);
|
||||
|
||||
Reference in New Issue
Block a user