Skip to content

Commit

Permalink
Check for fatal audio errors after creating a Music player.
Browse files Browse the repository at this point in the history
Show a friendly error when this happens and quit, or else some pretty nasty things can happen (like repeated trackEnded() action loops).

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Feb 3, 2017
1 parent f4a37d7 commit fca4fd4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/itdelatrisu/opsu/audio/MusicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,20 @@ else if (beatmap.previewTime != lastBeatmap.previewTime)
*/
private static void loadTrack(File file, int position, boolean loop) {
try {
// create the music player
// NOTE: most errors from this call are suppressed, so check
// for SoundStore errors manually afterwards
player = new Music(file.getPath(), true);
if (!SoundStore.get().soundWorks()) {
player = null;
trackEnded = false;
ErrorHandler.error(
"Sound isn't working right now. Sorry!\n" +
"Restarting the game will probably fix this.",
null, false
);
return;
}
player.addListener(new MusicListener() {
@Override
public void musicEnded(Music music) {
Expand Down

0 comments on commit fca4fd4

Please # to comment.