mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-11-01 01:05:19 +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;
|
Status status = Status.NOT_STARTED;
|
||||||
Media soundData;
|
Media soundData;
|
||||||
SoundBuffer playbackBuffer;
|
SoundBuffer playbackBuffer;
|
||||||
|
Duration lastKnownDuration = Duration.ZERO;
|
||||||
Executor executor = Executors.newSingleThreadExecutor();
|
Executor executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
public static enum Status {
|
public static enum Status {
|
||||||
@ -34,8 +35,12 @@ public class MediaPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Duration getCurrentTime() {
|
public Duration getCurrentTime() {
|
||||||
|
if (soundData == null) {
|
||||||
|
return lastKnownDuration;
|
||||||
|
} else {
|
||||||
return soundData.getCurrentTime();
|
return soundData.getCurrentTime();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public double getVolume() {
|
public double getVolume() {
|
||||||
return vol;
|
return vol;
|
||||||
@ -54,6 +59,7 @@ public class MediaPlayer {
|
|||||||
// Ignore exception on shutdown
|
// Ignore exception on shutdown
|
||||||
} finally {
|
} finally {
|
||||||
if (soundData != null) {
|
if (soundData != null) {
|
||||||
|
lastKnownDuration = soundData.getCurrentTime();
|
||||||
soundData.close();
|
soundData.close();
|
||||||
}
|
}
|
||||||
soundData = null;
|
soundData = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user