cleaned up code; status bar on main menu shows more info;

This commit is contained in:
Harrison Deng 2018-08-24 01:59:23 -05:00
parent b0b7be9141
commit b84a3d6280
3 changed files with 35 additions and 18 deletions

View File

@ -19,7 +19,7 @@ import com.badlogic.gdx.files.FileHandle;
*/ */
public class MusicController extends Observable implements OnCompletionListener, Observer { public class MusicController extends Observable implements OnCompletionListener, Observer {
public final class States { public final class States {
public final Integer LOADED = new Integer(0), PLAYING = new Integer(1); public final Integer LOADED = new Integer(0), PLAYING = new Integer(1), PAUSED = new Integer(2);
} }
public final States states = new States(); public final States states = new States();
@ -63,6 +63,8 @@ public class MusicController extends Observable implements OnCompletionListener,
public void pause() { public void pause() {
if (music != null) { if (music != null) {
music.pause(); music.pause();
setChanged();
notifyObservers(states.PAUSED);
} }
} }
@ -164,9 +166,7 @@ public class MusicController extends Observable implements OnCompletionListener,
currentlyPlayingIndex = 0; currentlyPlayingIndex = 0;
} }
if (musicList.getTotal() != 0) { if (musicList.getTotal() != 0) {
FileHandle musicFile = musicList.getAudioFileHandle(currentlyPlayingIndex); this.music = Gdx.audio.newMusic(musicList.getAudioFileHandle(currentlyPlayingIndex));
if (musicFile == null) return;
this.music = Gdx.audio.newMusic(musicFile);
music.setOnCompletionListener(this); music.setOnCompletionListener(this);
setChanged(); setChanged();

View File

@ -18,7 +18,7 @@ import zero1hd.rhythmbullet.audio.processor.WAVAudioProcessor;
*/ */
public class MusicList extends Observable { public class MusicList extends Observable {
public final class States { public final class States {
public final Integer LOADING = new Integer(0), COMPLETE = new Integer(1); public final Integer LOADING = new Integer(0), COMPLETE = new Integer(1), EMPTY = new Integer(2);
} }
public States states = new States(); public States states = new States();
private Array<FileHandle> musicList; private Array<FileHandle> musicList;
@ -73,6 +73,10 @@ public class MusicList extends Observable {
setChanged(); setChanged();
} }
public String getSearchPath() {
return searchPath;
}
/** /**
* @param file * @param file
* @return a {@link AudioProcessor} of the given music file. Will return null if theres a format error. * @return a {@link AudioProcessor} of the given music file. Will return null if theres a format error.
@ -122,14 +126,7 @@ public class MusicList extends Observable {
} }
public FileHandle getAudioFileHandle(int index) { public FileHandle getAudioFileHandle(int index) {
FileHandle file = musicList.get(index); return musicList.get(index);
if (file != null) {
return file;
}
asyncSearch(true);
return null;
} }
public int getIndexOfFileHandle(FileHandle file) { public int getIndexOfFileHandle(FileHandle file) {
@ -169,7 +166,11 @@ public class MusicList extends Observable {
searched = true; searched = true;
Gdx.app.debug("MusicList", "recursive async search completed."); Gdx.app.debug("MusicList", "recursive async search completed.");
setChanged(); setChanged();
notifyObservers(states.COMPLETE); if (musicList.size != 0) {
notifyObservers(states.COMPLETE);
} else {
notifyObservers(states.EMPTY);
}
} }
} }

View File

@ -47,6 +47,7 @@ public class MainPage extends Page implements Observer {
super(0, 0); super(0, 0);
this.mc = musicController; this.mc = musicController;
this.mc.addObserver(this); this.mc.addObserver(this);
mc.getMusicList().addObserver(this);
this.amc = mmc; this.amc = mmc;
this.amc.addObserver(this); this.amc.addObserver(this);
@ -116,21 +117,36 @@ public class MainPage extends Page implements Observer {
@Override @Override
public void dispose() { public void dispose() {
dhv.dispose(); dhv.dispose();
mc.getMusicList().deleteObserver(this);
super.dispose(); super.dispose();
} }
@Override @Override
public void update(Observable o, Object arg) { public void update(Observable o, Object arg) {
if (o == mc) { if (o == mc) {
if (amc.isSameSizeMusicList()) { if (arg == mc.states.LOADED) {
scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null); if (amc.isSameSizeMusicList()) {
} else { scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null);
scrollText.setText("Currently playing: " + mc.getCurrentMusicFileHandle().nameWithoutExtension().replace('_', ' '), null); } else {
scrollText.setText("Currently playing: " + mc.getCurrentMusicFileHandle().nameWithoutExtension().replace('_', ' '), null);
}
} else if (arg == mc.states.PAUSED) {
if (amc.isSameSizeMusicList()) {
scrollText.setText("Currently paused: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null);
} else {
scrollText.setText("Currently paused: " + mc.getCurrentMusicFileHandle().nameWithoutExtension().replace('_', ' '), null);
}
} }
} else if (o == amc) { } else if (o == amc) {
if (amc.size() != 0) { if (amc.size() != 0) {
scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null); scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null);
} }
} else if (o == mc.getMusicList()) {
if (arg == mc.getMusicList().states.EMPTY) {
scrollText.setText("Couldn't find MP3/WAV files", null);
} else if (arg == mc.getMusicList().states.LOADING) {
scrollText.setText("Loading...", null);
}
} }
} }
} }