Fixed a major memory leak caused by MusicController.getDuration().

Blame: f23159d

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-19 04:47:02 -04:00
parent b46c589b97
commit 7d5899ba7e

View File

@ -53,6 +53,9 @@ public class MusicController {
/** The last OsuFile passed to play(). */ /** The last OsuFile passed to play(). */
private static OsuFile lastOsu; private static OsuFile lastOsu;
/** The track duration. */
private static int duration = -1;
/** Thread for loading tracks. */ /** Thread for loading tracks. */
private static Thread trackLoader; private static Thread trackLoader;
@ -270,17 +273,21 @@ public class MusicController {
if (!trackExists() || lastOsu == null) if (!trackExists() || lastOsu == null)
return -1; return -1;
if (lastOsu.audioFilename.getName().endsWith(".mp3")) { if (duration == -1) {
try { if (lastOsu.audioFilename.getName().endsWith(".mp3")) {
AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(lastOsu.audioFilename); try {
if (fileFormat instanceof TAudioFileFormat) { AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(lastOsu.audioFilename);
Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties(); if (fileFormat instanceof TAudioFileFormat) {
Long microseconds = (Long) properties.get("duration"); Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties();
return (int) (microseconds / 1000); Long microseconds = (Long) properties.get("duration");
} duration = (int) (microseconds / 1000);
} catch (UnsupportedAudioFileException | IOException e) {} return duration;
}
} catch (UnsupportedAudioFileException | IOException e) {}
}
duration = lastOsu.endTime;
} }
return lastOsu.endTime; return duration;
} }
/** /**
@ -376,6 +383,7 @@ public class MusicController {
// reset state // reset state
lastOsu = null; lastOsu = null;
duration = -1;
trackEnded = false; trackEnded = false;
themePlaying = false; themePlaying = false;
pauseTime = 0f; pauseTime = 0f;