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 (duration == -1) {
if (lastOsu.audioFilename.getName().endsWith(".mp3")) { if (lastOsu.audioFilename.getName().endsWith(".mp3")) {
try { try {
AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(lastOsu.audioFilename); AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(lastOsu.audioFilename);
if (fileFormat instanceof TAudioFileFormat) { if (fileFormat instanceof TAudioFileFormat) {
Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties(); Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties();
Long microseconds = (Long) properties.get("duration"); Long microseconds = (Long) properties.get("duration");
return (int) (microseconds / 1000); duration = (int) (microseconds / 1000);
return duration;
} }
} catch (UnsupportedAudioFileException | IOException e) {} } catch (UnsupportedAudioFileException | IOException e) {}
} }
return lastOsu.endTime; duration = 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;