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("cybercircle3B.png", Texture.class);
|
||||||
assetManager.load("PolyjetTitle.png", Texture.class);
|
assetManager.load("PolyjetTitle.png", Texture.class);
|
||||||
assetManager.load("cybercircle1.png", Texture.class);
|
assetManager.load("cybercircle1.png", Texture.class);
|
||||||
|
assetManager.load("defaultCover.png", Texture.class);
|
||||||
}
|
}
|
||||||
public void generateFonts() {
|
public void generateFonts() {
|
||||||
initComplete = true;
|
initComplete = true;
|
||||||
|
@ -5,11 +5,14 @@ import java.io.IOException;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Preferences;
|
import com.badlogic.gdx.Preferences;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Button;
|
import com.badlogic.gdx.scenes.scene2d.ui.Button;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
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.scenes.scene2d.ui.Skin;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
import com.mpatric.mp3agic.ID3v2;
|
import com.mpatric.mp3agic.ID3v2;
|
||||||
import com.mpatric.mp3agic.InvalidDataException;
|
import com.mpatric.mp3agic.InvalidDataException;
|
||||||
import com.mpatric.mp3agic.Mp3File;
|
import com.mpatric.mp3agic.Mp3File;
|
||||||
@ -17,20 +20,24 @@ import com.mpatric.mp3agic.UnsupportedTagException;
|
|||||||
|
|
||||||
import zero1hd.wavedecoder.WavInfo;
|
import zero1hd.wavedecoder.WavInfo;
|
||||||
|
|
||||||
public class MusicSelectable extends Button {
|
public class MusicSelectable extends Button implements Disposable {
|
||||||
Image imageIcon;
|
private boolean invalidMusic;
|
||||||
FileHandle musicFile;
|
private long durationInSeconds;
|
||||||
boolean invalidMusic;
|
private String songName;
|
||||||
long durationInSeconds;
|
private Texture albumCover;
|
||||||
String songName;
|
|
||||||
|
|
||||||
WavInfo wavinfo;
|
WavInfo wavinfo;
|
||||||
private byte[] albumWorkBytes;
|
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");
|
super(skin, "info-button");
|
||||||
|
|
||||||
this.musicFile = musicFile;
|
debug();
|
||||||
|
|
||||||
|
this.albumCover = defaultAlbumC;
|
||||||
|
|
||||||
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
||||||
try {
|
try {
|
||||||
@ -54,24 +61,53 @@ public class MusicSelectable extends Button {
|
|||||||
if (durationInSeconds > 60 * 5) {
|
if (durationInSeconds > 60 * 5) {
|
||||||
invalidMusic = true;
|
invalidMusic = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (songName == null || songName.isEmpty()) {
|
if (songName == null || songName.isEmpty()) {
|
||||||
songName = musicFile.name();
|
songName = musicFile.nameWithoutExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gdx.app.postRunnable(new Runnable() {
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderAlbumCover() {
|
@Override
|
||||||
if (albumWorkBytes != null) {
|
public void dispose() {
|
||||||
Pixmap albumArt = new Pixmap(albumWorkBytes, 0, albumWorkBytes.length);
|
albumCover.dispose();
|
||||||
Texture albumArtTexture = new Texture(albumArt);
|
|
||||||
imageIcon = new Image(albumArtTexture);
|
|
||||||
float scale = 0.25f*getHeight()/imageIcon.getHeight();
|
|
||||||
imageIcon.setScale(scale);
|
|
||||||
|
|
||||||
add(imageIcon);
|
|
||||||
albumArtTexture.dispose();
|
|
||||||
} else {
|
|
||||||
//TODO load default album cover texture
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import java.io.FilenameFilter;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Preferences;
|
import com.badlogic.gdx.Preferences;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
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.Actor;
|
||||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||||
@ -81,7 +82,6 @@ public class MusicSelectionPage extends Page {
|
|||||||
this.skin = skin;
|
this.skin = skin;
|
||||||
this.musicDir = musicDir;
|
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++) {
|
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());
|
musicChoices.add(selectable).prefSize(0.2f*Gdx.graphics.getWidth(), 0.8f*Gdx.graphics.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,6 @@ public class WavInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getDurationInSeconds() {
|
public long getDurationInSeconds() {
|
||||||
return (long) (dataSize/sampleRate);
|
return (long) (dataSize/byteRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user