41 lines
906 B
Java
41 lines
906 B
Java
|
package envoy.client.ui;
|
||
|
|
||
|
import javafx.scene.control.Button;
|
||
|
import javafx.scene.layout.HBox;
|
||
|
|
||
|
import envoy.client.data.audio.AudioPlayer;
|
||
|
import envoy.exception.EnvoyException;
|
||
|
|
||
|
/**
|
||
|
* Enables the play back of audio clips through a button.
|
||
|
* <p>
|
||
|
* Project: <strong>envoy-client</strong><br>
|
||
|
* File: <strong>AudioControl.java</strong><br>
|
||
|
* Created: <strong>05.07.2020</strong><br>
|
||
|
*
|
||
|
* @author Kai S. K. Engelbart
|
||
|
* @since Envoy Client v0.1-beta
|
||
|
*/
|
||
|
public final class AudioControl extends HBox {
|
||
|
|
||
|
private AudioPlayer player = new AudioPlayer();
|
||
|
|
||
|
/**
|
||
|
* 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) {
|
||
|
|
||
|
}
|
||
|
});
|
||
|
getChildren().add(button);
|
||
|
}
|
||
|
}
|