finished adding album cover for music selection, properly read different wav headers now
This commit is contained in:
parent
3d52583de2
commit
dd729cffd7
Binary file not shown.
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 6.3 KiB |
@ -26,19 +26,18 @@ public class MusicSelectable extends Button implements Disposable {
|
||||
private String songName;
|
||||
private Texture albumCover;
|
||||
WavInfo wavinfo;
|
||||
private int previousTop;
|
||||
private int ratedDifficulty;
|
||||
private byte[] albumWorkBytes;
|
||||
|
||||
private volatile Image imageIcon;
|
||||
private Image imageIcon;
|
||||
private Label displayName;
|
||||
private Label runTime;
|
||||
private Skin skin;
|
||||
|
||||
public MusicSelectable(FileHandle musicFile, Preferences musicData, final Skin skin, Texture defaultAlbumC) {
|
||||
super(skin, "info-button");
|
||||
this.skin = skin;
|
||||
|
||||
debug();
|
||||
|
||||
this.albumCover = defaultAlbumC;
|
||||
|
||||
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
||||
@ -67,52 +66,61 @@ public class MusicSelectable extends Button implements Disposable {
|
||||
if (songName == null || songName.isEmpty()) {
|
||||
songName = musicFile.nameWithoutExtension();
|
||||
}
|
||||
|
||||
previousTop = musicData.getInteger(songName + ":previous top");
|
||||
ratedDifficulty = musicData.getInteger(songName + ":difficulty");
|
||||
}
|
||||
|
||||
public synchronized void addInfoToPanel() {
|
||||
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");
|
||||
}
|
||||
float scale = getWidth()/imageIcon.getWidth();
|
||||
imageIcon.setScale(scale);
|
||||
// imageIcon.setSize(scale*imageIcon.getWidth(), scale*imageIcon.getHeight());
|
||||
|
||||
|
||||
add(imageIcon);
|
||||
|
||||
row();
|
||||
|
||||
displayName = new Label(songName, skin);
|
||||
displayName.setWrap(true);
|
||||
add(displayName).prefWidth(getPrefWidth()-5).center();
|
||||
|
||||
|
||||
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 addInfoToPanel(float width) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
Gdx.app.debug("UI", "album cover invalid or null for image: " + songName);
|
||||
}
|
||||
add(imageIcon).prefSize(width, width).spaceBottom(20f);
|
||||
|
||||
|
||||
row();
|
||||
|
||||
displayName = new Label(songName, skin);
|
||||
displayName.setWrap(true);
|
||||
add(displayName).prefWidth(width-5).center();
|
||||
|
||||
|
||||
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 int getPreviousTop() {
|
||||
return previousTop;
|
||||
}
|
||||
|
||||
public int getRatedDifficulty() {
|
||||
return ratedDifficulty;
|
||||
}
|
||||
|
||||
public Texture getAlbumCover() {
|
||||
return albumCover;
|
||||
}
|
||||
|
||||
public WavInfo getWavinfo() {
|
||||
return wavinfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,6 @@ package zero1hd.polyjet.ui.pages;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
@ -12,7 +11,6 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
@ -66,45 +64,33 @@ public class MusicSelectionPage extends Page {
|
||||
}
|
||||
|
||||
public void beginMusicSearch() {
|
||||
Thread musicFinder = new Thread(new MusicFinderRunnable(Gdx.files.absolute(core.prefs.getString("music dir")), core.defaultSkin, 0));
|
||||
musicFinder.start();
|
||||
}
|
||||
|
||||
class MusicFinderRunnable implements Runnable {
|
||||
private FileHandle[] musicFiles;
|
||||
private int startingID;
|
||||
private Skin skin;
|
||||
private FileHandle musicDir;
|
||||
// private CountDownLatch latch;
|
||||
private volatile MusicSelectable selectable;
|
||||
|
||||
public MusicFinderRunnable(FileHandle musicDir, Skin skin, int startingID) {
|
||||
super();
|
||||
new Thread(new Runnable() {
|
||||
|
||||
this.startingID = startingID;
|
||||
this.skin = skin;
|
||||
this.musicDir = musicDir;
|
||||
|
||||
// latch = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
musicFiles = musicDir.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.endsWith("mp3") || name.endsWith("wav")) {
|
||||
return true;
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
FileHandle[] musicFiles = new FileHandle(core.prefs.getString("music dir")).list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.endsWith("mp3") || name.endsWith("wav")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
int startingID = 0;
|
||||
for (int music = startingID; music < musicFiles.length && music < 15; music++) {
|
||||
final MusicSelectable selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, core.defaultSkin, core.assetManager.get("defaultCover.png", Texture.class));
|
||||
Gdx.app.postRunnable(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
selectable.addInfoToPanel(0.2f*getWidth()-10);
|
||||
musicChoices.add(selectable).prefSize(0.2f*getWidth(), 0.8f*getHeight());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
for (int music = startingID; music < musicFiles.length && music < 15; music++) {
|
||||
selectable = new MusicSelectable(musicFiles[music], musicFileAnnotation, skin, core.assetManager.get("defaultCover.png", Texture.class));
|
||||
musicChoices.add(selectable).prefSize(0.2f*getWidth(), 0.8f*getHeight());
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,6 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
public class WavInfo {
|
||||
private int channels;
|
||||
private double sampleRate;
|
||||
@ -59,18 +57,18 @@ public class WavInfo {
|
||||
|
||||
byteRate = littleEndianIntBytes(); //4
|
||||
|
||||
readStream.skip(4); //38
|
||||
readStream.skip(4);
|
||||
|
||||
// System.out.println(readBytesToString(4).equals("data"));
|
||||
|
||||
if (!readBytesToString(4).equals("data")) { // 4
|
||||
Gdx.app.debug("Audio", "sample rate: " + sampleRate);
|
||||
Gdx.app.debug("Audio", "Data chunk size: " + dataSize);
|
||||
Gdx.app.debug("Audio", "Channel count: " + channels);
|
||||
|
||||
throw new InvalidParameterException("initial data section tag not found on wav: " + fileName);
|
||||
String moreInfo = readBytesToString(4);
|
||||
if (moreInfo.equals("LIST")) { // 4
|
||||
readStream.skip(30);
|
||||
if (!readBytesToString(4).equals("data")) {
|
||||
throw new InvalidParameterException("failed to read data with extra info.");
|
||||
}
|
||||
} else if (!moreInfo.equals("data")) {
|
||||
throw new InvalidParameterException("failed to read data.");
|
||||
}
|
||||
|
||||
|
||||
readStream.skip(4);
|
||||
}
|
||||
|
||||
@ -122,4 +120,8 @@ public class WavInfo {
|
||||
public long getDurationInSeconds() {
|
||||
return (long) (dataSize/byteRate);
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user