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 String songName;
|
||||||
private Texture albumCover;
|
private Texture albumCover;
|
||||||
WavInfo wavinfo;
|
WavInfo wavinfo;
|
||||||
|
private int previousTop;
|
||||||
|
private int ratedDifficulty;
|
||||||
private byte[] albumWorkBytes;
|
private byte[] albumWorkBytes;
|
||||||
|
|
||||||
private volatile Image imageIcon;
|
private Image imageIcon;
|
||||||
private Label displayName;
|
private Label displayName;
|
||||||
private Label runTime;
|
private Label runTime;
|
||||||
private Skin skin;
|
private Skin skin;
|
||||||
|
|
||||||
public MusicSelectable(FileHandle musicFile, Preferences musicData, final Skin skin, Texture defaultAlbumC) {
|
public MusicSelectable(FileHandle musicFile, Preferences musicData, final Skin skin, Texture defaultAlbumC) {
|
||||||
super(skin, "info-button");
|
super(skin, "info-button");
|
||||||
this.skin = skin;
|
this.skin = skin;
|
||||||
|
|
||||||
debug();
|
|
||||||
|
|
||||||
this.albumCover = defaultAlbumC;
|
this.albumCover = defaultAlbumC;
|
||||||
|
|
||||||
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
||||||
@ -67,52 +66,61 @@ public class MusicSelectable extends Button implements Disposable {
|
|||||||
if (songName == null || songName.isEmpty()) {
|
if (songName == null || songName.isEmpty()) {
|
||||||
songName = musicFile.nameWithoutExtension();
|
songName = musicFile.nameWithoutExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previousTop = musicData.getInteger(songName + ":previous top");
|
||||||
|
ratedDifficulty = musicData.getInteger(songName + ":difficulty");
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addInfoToPanel() {
|
public void addInfoToPanel(float width) {
|
||||||
Gdx.app.postRunnable(new Runnable() {
|
if (albumWorkBytes != null && !invalidMusic) {
|
||||||
|
Pixmap albumArt = new Pixmap(albumWorkBytes, 0, albumWorkBytes.length);
|
||||||
@Override
|
albumCover = new Texture(albumArt);
|
||||||
public void run() {
|
imageIcon = new Image(albumCover);
|
||||||
if (albumWorkBytes != null && !invalidMusic) {
|
albumArt.dispose();
|
||||||
Pixmap albumArt = new Pixmap(albumWorkBytes, 0, albumWorkBytes.length);
|
} else {
|
||||||
albumCover = new Texture(albumArt);
|
imageIcon = new Image(albumCover);
|
||||||
imageIcon = new Image(albumCover);
|
if (invalidMusic) {
|
||||||
albumArt.dispose();
|
imageIcon.setColor(Color.RED);
|
||||||
} 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);
|
|
||||||
}
|
}
|
||||||
});
|
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
|
@Override
|
||||||
|
@ -2,7 +2,6 @@ package zero1hd.polyjet.ui.pages;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Preferences;
|
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.actions.Actions;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
|
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.Table;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||||
@ -66,45 +64,33 @@ public class MusicSelectionPage extends Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void beginMusicSearch() {
|
public void beginMusicSearch() {
|
||||||
Thread musicFinder = new Thread(new MusicFinderRunnable(Gdx.files.absolute(core.prefs.getString("music dir")), core.defaultSkin, 0));
|
new Thread(new Runnable() {
|
||||||
musicFinder.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
class MusicFinderRunnable implements Runnable {
|
@Override
|
||||||
private FileHandle[] musicFiles;
|
public void run() {
|
||||||
private int startingID;
|
|
||||||
private Skin skin;
|
|
||||||
private FileHandle musicDir;
|
|
||||||
// private CountDownLatch latch;
|
|
||||||
private volatile MusicSelectable selectable;
|
|
||||||
|
|
||||||
public MusicFinderRunnable(FileHandle musicDir, Skin skin, int startingID) {
|
FileHandle[] musicFiles = new FileHandle(core.prefs.getString("music dir")).list(new FilenameFilter() {
|
||||||
super();
|
@Override
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
this.startingID = startingID;
|
if (name.endsWith("mp3") || name.endsWith("wav")) {
|
||||||
this.skin = skin;
|
return true;
|
||||||
this.musicDir = musicDir;
|
}
|
||||||
|
return false;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
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.io.IOException;
|
||||||
import java.security.InvalidParameterException;
|
import java.security.InvalidParameterException;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
|
|
||||||
public class WavInfo {
|
public class WavInfo {
|
||||||
private int channels;
|
private int channels;
|
||||||
private double sampleRate;
|
private double sampleRate;
|
||||||
@ -59,16 +57,16 @@ public class WavInfo {
|
|||||||
|
|
||||||
byteRate = littleEndianIntBytes(); //4
|
byteRate = littleEndianIntBytes(); //4
|
||||||
|
|
||||||
readStream.skip(4); //38
|
readStream.skip(4);
|
||||||
|
|
||||||
// System.out.println(readBytesToString(4).equals("data"));
|
String moreInfo = readBytesToString(4);
|
||||||
|
if (moreInfo.equals("LIST")) { // 4
|
||||||
if (!readBytesToString(4).equals("data")) { // 4
|
readStream.skip(30);
|
||||||
Gdx.app.debug("Audio", "sample rate: " + sampleRate);
|
if (!readBytesToString(4).equals("data")) {
|
||||||
Gdx.app.debug("Audio", "Data chunk size: " + dataSize);
|
throw new InvalidParameterException("failed to read data with extra info.");
|
||||||
Gdx.app.debug("Audio", "Channel count: " + channels);
|
}
|
||||||
|
} else if (!moreInfo.equals("data")) {
|
||||||
throw new InvalidParameterException("initial data section tag not found on wav: " + fileName);
|
throw new InvalidParameterException("failed to read data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
readStream.skip(4);
|
readStream.skip(4);
|
||||||
@ -122,4 +120,8 @@ public class WavInfo {
|
|||||||
public long getDurationInSeconds() {
|
public long getDurationInSeconds() {
|
||||||
return (long) (dataSize/byteRate);
|
return (long) (dataSize/byteRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user