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 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();
@ -63,6 +63,8 @@ public class MusicController extends Observable implements OnCompletionListener,
public void pause() {
if (music != null) {
music.pause();
setChanged();
notifyObservers(states.PAUSED);
}
}
@ -164,9 +166,7 @@ public class MusicController extends Observable implements OnCompletionListener,
currentlyPlayingIndex = 0;
}
if (musicList.getTotal() != 0) {
FileHandle musicFile = musicList.getAudioFileHandle(currentlyPlayingIndex);
if (musicFile == null) return;
this.music = Gdx.audio.newMusic(musicFile);
this.music = Gdx.audio.newMusic(musicList.getAudioFileHandle(currentlyPlayingIndex));
music.setOnCompletionListener(this);
setChanged();

View File

@ -18,7 +18,7 @@ import zero1hd.rhythmbullet.audio.processor.WAVAudioProcessor;
*/
public class MusicList extends Observable {
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();
private Array<FileHandle> musicList;
@ -73,6 +73,10 @@ public class MusicList extends Observable {
setChanged();
}
public String getSearchPath() {
return searchPath;
}
/**
* @param file
* @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) {
FileHandle file = musicList.get(index);
if (file != null) {
return file;
}
asyncSearch(true);
return null;
return musicList.get(index);
}
public int getIndexOfFileHandle(FileHandle file) {
@ -169,7 +166,11 @@ public class MusicList extends Observable {
searched = true;
Gdx.app.debug("MusicList", "recursive async search completed.");
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);
this.mc = musicController;
this.mc.addObserver(this);
mc.getMusicList().addObserver(this);
this.amc = mmc;
this.amc.addObserver(this);
@ -116,21 +117,36 @@ public class MainPage extends Page implements Observer {
@Override
public void dispose() {
dhv.dispose();
mc.getMusicList().deleteObserver(this);
super.dispose();
}
@Override
public void update(Observable o, Object arg) {
if (o == mc) {
if (amc.isSameSizeMusicList()) {
scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), null);
} else {
scrollText.setText("Currently playing: " + mc.getCurrentMusicFileHandle().nameWithoutExtension().replace('_', ' '), null);
if (arg == mc.states.LOADED) {
if (amc.isSameSizeMusicList()) {
scrollText.setText("Currently playing: " + amc.getAudioMetadata(mc.getCurrentMusicFileHandle()).getTitle(), 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) {
if (amc.size() != 0) {
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);
}
}
}
}