From 03a159642006a9c7afa5e61a1049793e174632ee Mon Sep 17 00:00:00 2001 From: kske Date: Sun, 5 Jul 2020 14:25:58 +0200 Subject: [PATCH] Add Exception Logging --- .../java/envoy/client/data/audio/AudioRecorder.java | 3 +++ src/main/java/envoy/client/ui/AudioControl.java | 11 ++++++++++- .../java/envoy/client/ui/controller/ChatScene.java | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/envoy/client/data/audio/AudioRecorder.java b/src/main/java/envoy/client/data/audio/AudioRecorder.java index a59043f..c6a4ed2 100644 --- a/src/main/java/envoy/client/data/audio/AudioRecorder.java +++ b/src/main/java/envoy/client/data/audio/AudioRecorder.java @@ -115,5 +115,8 @@ public final class AudioRecorder { public void cancel() { line.stop(); line.close(); + try { + Files.deleteIfExists(tempFile); + } catch (IOException e) {} } } diff --git a/src/main/java/envoy/client/ui/AudioControl.java b/src/main/java/envoy/client/ui/AudioControl.java index 698e315..eca232f 100644 --- a/src/main/java/envoy/client/ui/AudioControl.java +++ b/src/main/java/envoy/client/ui/AudioControl.java @@ -1,10 +1,16 @@ 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. @@ -20,6 +26,8 @@ public final class AudioControl extends HBox { private AudioPlayer player = new AudioPlayer(); + private static final Logger logger = EnvoyLog.getLogger(AudioControl.class); + /** * Initializes the audio control. * @@ -32,7 +40,8 @@ public final class AudioControl extends HBox { 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); diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 2ebfbd8..ffe74b5 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -263,7 +263,8 @@ public final class ChatScene { Platform.runLater(() -> { voiceButton.setText("Record Voice Message"); checkPostConditions(false); }); } } catch (EnvoyException e) { - e.printStackTrace(); + logger.log(Level.SEVERE, "Could not record audio: ", e); + Platform.runLater(new Alert(AlertType.ERROR, "Could not record audio")::showAndWait); } }).start(); }