Cleaned up a bit
This commit is contained in:
		@@ -10,27 +10,27 @@ import envoy.exception.EnvoyException;
 | 
			
		||||
 * Project: <strong>envoy-client</strong><br>
 | 
			
		||||
 * File: <strong>AudioPlayer.java</strong><br>
 | 
			
		||||
 * Created: <strong>05.07.2020</strong><br>
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @author Kai S. K. Engelbart
 | 
			
		||||
 * @since Envoy Client v0.1-beta
 | 
			
		||||
 */
 | 
			
		||||
public final class AudioPlayer {
 | 
			
		||||
 | 
			
		||||
	private final AudioFormat format;
 | 
			
		||||
	private final AudioFormat	format;
 | 
			
		||||
	private final DataLine.Info	info;
 | 
			
		||||
 | 
			
		||||
	private Clip clip;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes the player with the default audio format.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public AudioPlayer() { this(AudioRecorder.DEFAULT_AUDIO_FORMAT); }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes the player with a given audio format.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param format the audio format to use
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
@@ -47,7 +47,7 @@ public final class AudioPlayer {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Plays back an audio clip.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param data the data of the clip
 | 
			
		||||
	 * @throws EnvoyException if the play back failed
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
@@ -57,7 +57,7 @@ public final class AudioPlayer {
 | 
			
		||||
			clip = (Clip) AudioSystem.getLine(info);
 | 
			
		||||
			clip.open(format, data, 0, data.length);
 | 
			
		||||
			clip.start();
 | 
			
		||||
		} catch (LineUnavailableException e) {
 | 
			
		||||
		} catch (final LineUnavailableException e) {
 | 
			
		||||
			throw new EnvoyException("Cannot play back audio", e);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ public final class AudioRecorder {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * The default audio format used for recording and play back.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public static final AudioFormat DEFAULT_AUDIO_FORMAT = new AudioFormat(16000, 16, 1, true, false);
 | 
			
		||||
@@ -35,14 +35,14 @@ public final class AudioRecorder {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes the recorder with the default audio format.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public AudioRecorder() { this(DEFAULT_AUDIO_FORMAT); }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes the recorder with a given audio format.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param format the audio format to use
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
@@ -65,7 +65,7 @@ public final class AudioRecorder {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Starts the audio recording.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @throws EnvoyException if starting the recording failed
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
@@ -81,7 +81,7 @@ public final class AudioRecorder {
 | 
			
		||||
			tempFile = Files.createTempFile("recording", "wav");
 | 
			
		||||
 | 
			
		||||
			// Start the recording
 | 
			
		||||
			var ais = new AudioInputStream(line);
 | 
			
		||||
			final var ais = new AudioInputStream(line);
 | 
			
		||||
			AudioSystem.write(ais, AudioFileFormat.Type.WAVE, tempFile.toFile());
 | 
			
		||||
		} catch (IOException | LineUnavailableException e) {
 | 
			
		||||
			throw new EnvoyException("Cannot record voice", e);
 | 
			
		||||
@@ -90,7 +90,7 @@ public final class AudioRecorder {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Stops the recording.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @return the finished recording
 | 
			
		||||
	 * @throws EnvoyException if finishing the recording failed
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
@@ -99,17 +99,17 @@ public final class AudioRecorder {
 | 
			
		||||
		try {
 | 
			
		||||
			line.stop();
 | 
			
		||||
			line.close();
 | 
			
		||||
			byte[] data = Files.readAllBytes(tempFile);
 | 
			
		||||
			final byte[] data = Files.readAllBytes(tempFile);
 | 
			
		||||
			Files.delete(tempFile);
 | 
			
		||||
			return data;
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
		} catch (final IOException e) {
 | 
			
		||||
			throw new EnvoyException("Cannot save voice recording", e);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Cancels the active recording.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void cancel() {
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ import envoy.util.EnvoyLog;
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
@@ -30,7 +30,7 @@ public final class AudioControl extends HBox {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Initializes the audio control.
 | 
			
		||||
	 * 
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param audioData the audio data to play.
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,6 @@ import javafx.scene.layout.VBox;
 | 
			
		||||
 | 
			
		||||
import envoy.client.ui.AudioControl;
 | 
			
		||||
import envoy.client.ui.IconUtil;
 | 
			
		||||
import envoy.data.Attachment.AttachmentType;
 | 
			
		||||
import envoy.data.Message;
 | 
			
		||||
import envoy.data.Message.MessageStatus;
 | 
			
		||||
import envoy.data.User;
 | 
			
		||||
@@ -41,9 +40,18 @@ public class MessageControl extends VBox {
 | 
			
		||||
		// Creating the underlying VBox, the dateLabel and the textLabel
 | 
			
		||||
		super(new Label(dateFormat.format(message.getCreationDate())));
 | 
			
		||||
 | 
			
		||||
		// Voice attachment
 | 
			
		||||
		if (message.hasAttachment() && message.getAttachment().getType() == AttachmentType.VOICE)
 | 
			
		||||
			getChildren().add(new AudioControl(message.getAttachment().getData()));
 | 
			
		||||
		// Handling message attachment display
 | 
			
		||||
		if (message.hasAttachment()) switch (message.getAttachment().getType()) {
 | 
			
		||||
			case PICTURE:
 | 
			
		||||
				break;
 | 
			
		||||
			case VIDEO:
 | 
			
		||||
				break;
 | 
			
		||||
			case VOICE:
 | 
			
		||||
				getChildren().add(new AudioControl(message.getAttachment().getData()));
 | 
			
		||||
				break;
 | 
			
		||||
			case DOCUMENT:
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		final var textLabel = new Label(message.getText());
 | 
			
		||||
		textLabel.setWrapText(true);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
.button, .list-cell {
 | 
			
		||||
.button, .list-cell, .progress-bar * {
 | 
			
		||||
	-fx-background-radius: 5.0em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -26,6 +26,10 @@
 | 
			
		||||
	-fx-text-fill: transparent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.progress-bar{
 | 
			
		||||
	-fx-progress-color: blue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.online {
 | 
			
		||||
	-fx-text-fill: limegreen;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user