From f9321da4cd20f948c8bcb4e37e1f890f16a3c469 Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Sun, 25 Feb 2024 21:10:39 -0600 Subject: [PATCH] Prevent null pointer with getting media time --- .../jace/src/main/java/jace/lawless/MediaPlayer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Platform/Apple/tools/jace/src/main/java/jace/lawless/MediaPlayer.java b/Platform/Apple/tools/jace/src/main/java/jace/lawless/MediaPlayer.java index 7c02d843..96d56a5f 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/lawless/MediaPlayer.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/lawless/MediaPlayer.java @@ -17,6 +17,7 @@ public class MediaPlayer { Status status = Status.NOT_STARTED; Media soundData; SoundBuffer playbackBuffer; + Duration lastKnownDuration = Duration.ZERO; Executor executor = Executors.newSingleThreadExecutor(); public static enum Status { @@ -34,7 +35,11 @@ public class MediaPlayer { } public Duration getCurrentTime() { - return soundData.getCurrentTime(); + if (soundData == null) { + return lastKnownDuration; + } else { + return soundData.getCurrentTime(); + } } public double getVolume() { @@ -54,6 +59,7 @@ public class MediaPlayer { // Ignore exception on shutdown } finally { if (soundData != null) { + lastKnownDuration = soundData.getCurrentTime(); soundData.close(); } soundData = null;