mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-10-31 10:16:07 +00:00
Prevent null pointer with getting media time
This commit is contained in:
parent
56e524c9ad
commit
f9321da4cd
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user