package envoy.client.ui; import java.util.logging.Level; import java.util.logging.Logger; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import envoy.client.data.audio.AudioPlayer; import envoy.exception.EnvoyException; import envoy.util.EnvoyLog; /** * Enables the play back of audio clips through a button. *
* Project: envoy-client
* File: AudioControl.java
* Created: 05.07.2020
*
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
public final class AudioControl extends HBox {
private AudioPlayer player = new AudioPlayer();
private static final Logger logger = EnvoyLog.getLogger(AudioControl.class);
/**
* Initializes the audio control.
*
* @param audioData the audio data to play.
* @since Envoy Client v0.1-beta
*/
public AudioControl(byte[] audioData) {
var button = new Button("Play");
button.setOnAction(e -> {
try {
player.play(audioData);
} catch (EnvoyException ex) {
logger.log(Level.SEVERE, "Could not play back audio: ", ex);
new Alert(AlertType.ERROR, "Could not play back audio").showAndWait();
}
});
getChildren().add(button);
}
}