began music panel ui layout setup
This commit is contained in:
parent
ca8316892a
commit
173da4f6cd
@ -116,6 +116,7 @@ public class Polyjet extends Game {
|
||||
assetManager.load("cybercircle3B.png", Texture.class);
|
||||
assetManager.load("PolyjetTitle.png", Texture.class);
|
||||
assetManager.load("cybercircle1.png", Texture.class);
|
||||
assetManager.load("defaultCover.png", Texture.class);
|
||||
}
|
||||
public void generateFonts() {
|
||||
initComplete = true;
|
||||
|
@ -5,11 +5,14 @@ import java.io.IOException;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.mpatric.mp3agic.ID3v2;
|
||||
import com.mpatric.mp3agic.InvalidDataException;
|
||||
import com.mpatric.mp3agic.Mp3File;
|
||||
@ -17,20 +20,24 @@ import com.mpatric.mp3agic.UnsupportedTagException;
|
||||
|
||||
import zero1hd.wavedecoder.WavInfo;
|
||||
|
||||
public class MusicSelectable extends Button {
|
||||
Image imageIcon;
|
||||
FileHandle musicFile;
|
||||
boolean invalidMusic;
|
||||
long durationInSeconds;
|
||||
String songName;
|
||||
|
||||
public class MusicSelectable extends Button implements Disposable {
|
||||
private boolean invalidMusic;
|
||||
private long durationInSeconds;
|
||||
private String songName;
|
||||
private Texture albumCover;
|
||||
WavInfo wavinfo;
|
||||
private byte[] albumWorkBytes;
|
||||
|
||||
public MusicSelectable(FileHandle musicFile, Preferences musicData, Skin skin) {
|
||||
private Image imageIcon;
|
||||
private Label displayName;
|
||||
private Label runTime;
|
||||
|
||||
public MusicSelectable(FileHandle musicFile, Preferences musicData, final Skin skin, Texture defaultAlbumC) {
|
||||
super(skin, "info-button");
|
||||
|
||||
this.musicFile = musicFile;
|
||||
debug();
|
||||
|
||||
this.albumCover = defaultAlbumC;
|
||||
|
||||
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
||||
try {
|
||||
@ -54,24 +61,53 @@ public class MusicSelectable extends Button {
|
||||
if (durationInSeconds > 60 * 5) {
|
||||
invalidMusic = true;
|
||||
}
|
||||
|
||||
if (songName == null || songName.isEmpty()) {
|
||||
songName = musicFile.name();
|
||||
songName = musicFile.nameWithoutExtension();
|
||||
}
|
||||
}
|
||||
|
||||
public void renderAlbumCover() {
|
||||
if (albumWorkBytes != null) {
|
||||
Pixmap albumArt = new Pixmap(albumWorkBytes, 0, albumWorkBytes.length);
|
||||
Texture albumArtTexture = new Texture(albumArt);
|
||||
imageIcon = new Image(albumArtTexture);
|
||||
float scale = 0.25f*getHeight()/imageIcon.getHeight();
|
||||
imageIcon.setScale(scale);
|
||||
|
||||
Gdx.app.postRunnable(new Runnable() {
|
||||
|
||||
add(imageIcon);
|
||||
albumArtTexture.dispose();
|
||||
} else {
|
||||
//TODO load default album cover texture
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
if (albumWorkBytes != null && !invalidMusic) {
|
||||
Pixmap albumArt = new Pixmap(albumWorkBytes, 0, albumWorkBytes.length);
|
||||
albumCover = new Texture(albumArt);
|
||||
imageIcon = new Image(albumCover);
|
||||
albumArt.dispose();
|
||||
} else {
|
||||
imageIcon = new Image(albumCover);
|
||||
if (invalidMusic) {
|
||||
imageIcon.setColor(Color.RED);
|
||||
}
|
||||
System.out.println("invalid or null");
|
||||
}
|
||||
|
||||
add(imageIcon);
|
||||
|
||||
row();
|
||||
|
||||
displayName = new Label(songName, skin);
|
||||
displayName.setWrap(true);
|
||||
add(displayName).prefWidth(getWidth()-5);
|
||||
|
||||
row();
|
||||
|
||||
String formattedSecond = String.valueOf(durationInSeconds/60) + ":";
|
||||
|
||||
if (durationInSeconds - (durationInSeconds/60)*60 < 10) {
|
||||
formattedSecond = formattedSecond.concat("0");
|
||||
}
|
||||
|
||||
formattedSecond = formattedSecond.concat(String.valueOf(durationInSeconds - (durationInSeconds/60)*60));
|
||||
runTime = new Label(formattedSecond, skin);
|
||||
add(runTime);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
albumCover.dispose();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.io.FilenameFilter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
@ -81,7 +82,6 @@ public class MusicSelectionPage extends Page {
|
||||
this.skin = skin;
|
||||
this.musicDir = musicDir;
|
||||
|
||||
// System.out.println(musicDir.exists());
|
||||
}
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ public class MusicSelectionPage extends Page {
|
||||
}
|
||||
});
|
||||
for (int music = startingID; music < musicFiles.length && music < 15; music++) {
|
||||
MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, skin);
|
||||
MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, skin, core.assetManager.get("defaultCover.png", Texture.class));
|
||||
musicChoices.add(selectable).prefSize(0.2f*Gdx.graphics.getWidth(), 0.8f*Gdx.graphics.getHeight());
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,6 @@ public class WavInfo {
|
||||
}
|
||||
|
||||
public long getDurationInSeconds() {
|
||||
return (long) (dataSize/sampleRate);
|
||||
return (long) (dataSize/byteRate);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user