Skip to content

Commit

Permalink
Merge pull request #146 from Feodor0090/fallback-audio
Browse files Browse the repository at this point in the history
Allow audio to fallback to system time
  • Loading branch information
Feodor0090 authored May 14, 2023
2 parents ac74268 + 9a083c1 commit 78a3331
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions src/nmania/AudioController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
* @author Feodor0090
*
*/
public final class AudioController {
public class AudioController {

public AudioController(Beatmap map) throws IOException, MediaException {
this(map.ToGlobalPath(map.audio));
public AudioController(Beatmap map, boolean allowFallback) throws IOException, MediaException {
this(map.ToGlobalPath(map.audio), allowFallback);
}

public AudioController(BeatmapSet set) throws IOException, MediaException {
this(set.ToGlobalPath(set.audio));
public AudioController(BeatmapSet set, boolean allowFallback) throws IOException, MediaException {
this(set.ToGlobalPath(set.audio), allowFallback);
}

public AudioController(String file) throws MediaException, IOException {
public AudioController(String file, boolean allowFallback) throws MediaException, IOException {
Player p = TryInit(file, null);
if (p == null)
p = TryInit(file, "mp3");
Expand All @@ -32,7 +32,7 @@ public AudioController(String file) throws MediaException, IOException {
p = TryInit(file, "amr");
if (p == null)
p = TryInit(file, "wav");
if (p == null)
if (p == null && !allowFallback)
throw new IOException("Could not load any files on this MRL");
player = p;
offset = Settings.gameplayOffset;
Expand Down Expand Up @@ -65,8 +65,7 @@ private final Player TryInit(String mrl, String ext) throws MediaException {
p.prefetch();
return p;
} catch (MediaException e) {
if (e.toString().indexOf("not") != -1 && e.toString().indexOf("allowed") != -1)
throw e;
e.printStackTrace();
return null;
} catch (IOException e) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/nmania/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Player(Beatmap map, PlayerBootstrapData opts, Skin s, ILogger log, Displa

// step 2: loading music
log.log("Loading music");
track = new AudioController(map);
track = new AudioController(map, true);
Thread.sleep(1);

// step 3: setup difficulty
Expand Down
2 changes: 1 addition & 1 deletion src/nmania/ui/ng/NmaniaDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public void SetAudio(BeatmapSet set) {
}
try {
GL.Log("(ui) Loading new music...");
music = new AudioController(set);
music = new AudioController(set, false);
music.Loop();
music.Play();
music.SetTimingData(set.timings);
Expand Down

0 comments on commit 78a3331

Please sign in to comment.