music selection ui layout changed
This commit is contained in:
parent
b4c92a4477
commit
f57602788e
@ -48,7 +48,7 @@ project(":desktop") {
|
|||||||
|
|
||||||
compile "com.github.rwl:jtransforms:2.4.0"
|
compile "com.github.rwl:jtransforms:2.4.0"
|
||||||
|
|
||||||
compile "com.mpatric:mp3agic:0.9.0"
|
compile "org:jaudiotagger:2.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ project(":android") {
|
|||||||
|
|
||||||
compile "com.github.rwl:jtransforms:2.4.0"
|
compile "com.github.rwl:jtransforms:2.4.0"
|
||||||
|
|
||||||
compile "com.mpatric:mp3agic:0.9.0"
|
compile "org:jaudiotagger:2.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ project(":core") {
|
|||||||
|
|
||||||
compile "com.github.rwl:jtransforms:2.4.0"
|
compile "com.github.rwl:jtransforms:2.4.0"
|
||||||
|
|
||||||
compile "com.mpatric:mp3agic:0.9.0"
|
compile "org:jaudiotagger:2.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,15 @@ package zero1hd.polyjet.ui.builders;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jaudiotagger.audio.AudioFileIO;
|
||||||
|
import org.jaudiotagger.audio.exceptions.CannotReadException;
|
||||||
|
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
|
||||||
|
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
|
||||||
|
import org.jaudiotagger.audio.mp3.MP3File;
|
||||||
|
import org.jaudiotagger.audio.wav.WavTag;
|
||||||
|
import org.jaudiotagger.tag.FieldKey;
|
||||||
|
import org.jaudiotagger.tag.TagException;
|
||||||
|
|
||||||
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;
|
||||||
@ -12,11 +21,9 @@ 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.Label;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||||
|
import com.badlogic.gdx.utils.Align;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
import com.mpatric.mp3agic.ID3v2;
|
|
||||||
import com.mpatric.mp3agic.InvalidDataException;
|
|
||||||
import com.mpatric.mp3agic.Mp3File;
|
|
||||||
import com.mpatric.mp3agic.UnsupportedTagException;
|
|
||||||
|
|
||||||
import zero1hd.wavedecoder.WavInfo;
|
import zero1hd.wavedecoder.WavInfo;
|
||||||
|
|
||||||
@ -26,6 +33,7 @@ public class MusicSelectable extends Button implements Disposable {
|
|||||||
private String songName;
|
private String songName;
|
||||||
private Texture albumCover;
|
private Texture albumCover;
|
||||||
WavInfo wavinfo;
|
WavInfo wavinfo;
|
||||||
|
private String author;
|
||||||
private int previousTop;
|
private int previousTop;
|
||||||
private int ratedDifficulty;
|
private int ratedDifficulty;
|
||||||
private byte[] albumWorkBytes;
|
private byte[] albumWorkBytes;
|
||||||
@ -33,6 +41,9 @@ public class MusicSelectable extends Button implements Disposable {
|
|||||||
private Image imageIcon;
|
private Image imageIcon;
|
||||||
private ScrollText displayName;
|
private ScrollText displayName;
|
||||||
private Label runTime;
|
private Label runTime;
|
||||||
|
private Label authorLabel;
|
||||||
|
private Label previousTopLabel;
|
||||||
|
private Label ratedDifficultyLabel;
|
||||||
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");
|
||||||
@ -41,23 +52,36 @@ public class MusicSelectable extends Button implements Disposable {
|
|||||||
this.albumCover = defaultAlbumC;
|
this.albumCover = defaultAlbumC;
|
||||||
|
|
||||||
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
if (musicFile.extension().toLowerCase().equals("mp3")) {
|
||||||
|
MP3File mp3File;
|
||||||
try {
|
try {
|
||||||
Mp3File mp3File = new Mp3File(musicFile.file());
|
mp3File = new MP3File(musicFile.file());
|
||||||
durationInSeconds = mp3File.getLengthInSeconds();
|
durationInSeconds = mp3File.getAudioHeader().getTrackLength();
|
||||||
|
|
||||||
if (mp3File.hasId3v2Tag()) {
|
if (mp3File.getTag() != null) {
|
||||||
ID3v2 id3v2tag = mp3File.getId3v2Tag();
|
albumWorkBytes = mp3File.getTag().getFirstArtwork().getBinaryData();
|
||||||
albumWorkBytes = id3v2tag.getAlbumImage();
|
}
|
||||||
|
|
||||||
songName = id3v2tag.getTitle();
|
songName = mp3File.getTag().getFirst(FieldKey.TITLE);
|
||||||
}
|
author = mp3File.getTag().getFirst(FieldKey.ARTIST);
|
||||||
} catch (UnsupportedTagException | InvalidDataException | IOException e) {
|
} catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||||
Gdx.app.debug("Music Selector", "Error while reading tag for " + musicFile.name());
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
wavinfo = new WavInfo(musicFile.file());
|
wavinfo = new WavInfo(musicFile.file());
|
||||||
durationInSeconds = wavinfo.getDurationInSeconds();
|
durationInSeconds = wavinfo.getDurationInSeconds();
|
||||||
|
|
||||||
|
try {
|
||||||
|
WavTag wavTag = (WavTag) AudioFileIO.read(wavinfo.getFile()).getTag();
|
||||||
|
songName = wavTag.getFirst(FieldKey.TITLE);
|
||||||
|
author = wavTag.getFirst(FieldKey.ARTIST);
|
||||||
|
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException
|
||||||
|
| InvalidAudioFrameException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (durationInSeconds > 60 * 5) {
|
if (durationInSeconds > 60 * 5) {
|
||||||
invalidMusic = true;
|
invalidMusic = true;
|
||||||
@ -69,23 +93,47 @@ public class MusicSelectable extends Button implements Disposable {
|
|||||||
|
|
||||||
previousTop = musicData.getInteger(songName + ":previous top");
|
previousTop = musicData.getInteger(songName + ":previous top");
|
||||||
ratedDifficulty = musicData.getInteger(songName + ":difficulty");
|
ratedDifficulty = musicData.getInteger(songName + ":difficulty");
|
||||||
|
|
||||||
|
if (author == null || author.isEmpty()) {
|
||||||
|
author = "N/A";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addInfoToPanel() {
|
public void addInfoToPanel() {
|
||||||
displayName = new ScrollText(songName, skin, true);
|
displayName = new ScrollText(songName, skin, true);
|
||||||
|
|
||||||
add(displayName).fillX().spaceBottom(20f);
|
defaults().align(Align.top);
|
||||||
|
|
||||||
|
add(displayName).fillX().padTop(15f).top();
|
||||||
row();
|
row();
|
||||||
|
|
||||||
String formattedTime = "Run time: "+ String.valueOf(durationInSeconds/60) + ":";
|
String formattedTime = "Run time: "+ String.valueOf(durationInSeconds/60) + ":";
|
||||||
if (durationInSeconds - (durationInSeconds/60)*60 < 10) {
|
if (durationInSeconds - (durationInSeconds/60)*60 < 10) {
|
||||||
formattedTime = formattedTime.concat("0");
|
formattedTime = formattedTime.concat("0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Table songInfoTable = new Table();
|
||||||
|
|
||||||
formattedTime = formattedTime.concat(String.valueOf(durationInSeconds - (durationInSeconds/60)*60));
|
formattedTime = formattedTime.concat(String.valueOf(durationInSeconds - (durationInSeconds/60)*60));
|
||||||
runTime = new Label(formattedTime, skin, "sub-font", skin.getColor("default"));
|
runTime = new Label(formattedTime, skin, "sub-font", skin.getColor("default"));
|
||||||
add(runTime);
|
songInfoTable.add(runTime).center();
|
||||||
|
songInfoTable.row();
|
||||||
|
|
||||||
|
authorLabel = new Label("Author: " + author, skin, "sub-font", skin.getColor("default"));
|
||||||
|
songInfoTable.add(authorLabel).expandY();
|
||||||
|
songInfoTable.row();
|
||||||
|
|
||||||
|
previousTopLabel = new Label("Previous Top: " + previousTop, skin, "sub-font", skin.getColor("default"));
|
||||||
|
songInfoTable.add(previousTopLabel).center();
|
||||||
|
songInfoTable.row();
|
||||||
|
|
||||||
|
ratedDifficultyLabel = new Label("Difficulty: " + ratedDifficulty, skin, "sub-font", skin.getColor("default"));
|
||||||
|
songInfoTable.add(ratedDifficultyLabel).expandY();
|
||||||
|
songInfoTable.row();
|
||||||
|
|
||||||
|
row();
|
||||||
|
add(songInfoTable).expandY().center();
|
||||||
row();
|
row();
|
||||||
|
|
||||||
if (albumWorkBytes != null && !invalidMusic) {
|
if (albumWorkBytes != null && !invalidMusic) {
|
||||||
@ -100,7 +148,7 @@ public class MusicSelectable extends Button implements Disposable {
|
|||||||
}
|
}
|
||||||
Gdx.app.debug("UI", "album cover invalid or null for image: " + songName);
|
Gdx.app.debug("UI", "album cover invalid or null for image: " + songName);
|
||||||
}
|
}
|
||||||
add(imageIcon);
|
add(imageIcon).size(246f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreviousTop() {
|
public int getPreviousTop() {
|
||||||
|
@ -51,6 +51,12 @@ public class ScrollText extends Widget {
|
|||||||
currentlyHovering = false;
|
currentlyHovering = false;
|
||||||
super.exit(event, x, y, pointer, toActor);
|
super.exit(event, x, y, pointer, toActor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,7 +78,7 @@ public class ScrollText extends Widget {
|
|||||||
@Override
|
@Override
|
||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
if (scrollOnHover) {
|
if (scrollOnHover) {
|
||||||
if (currentlyHovering) {
|
if ((int) textOffset != 0 || currentlyHovering) {
|
||||||
if (textOffset < -fontWidth) {
|
if (textOffset < -fontWidth) {
|
||||||
textOffset = clipBounds.getWidth();
|
textOffset = clipBounds.getWidth();
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,11 @@ public class WavInfo {
|
|||||||
private DataInputStream readStream;
|
private DataInputStream readStream;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
|
private File file;
|
||||||
public WavInfo(File file) throws InvalidParameterException {
|
public WavInfo(File file) throws InvalidParameterException {
|
||||||
try {
|
try {
|
||||||
fileName = file.getName();
|
fileName = file.getName();
|
||||||
|
this.file = file;
|
||||||
audioFile = new FileInputStream(file);
|
audioFile = new FileInputStream(file);
|
||||||
initDataStream();
|
initDataStream();
|
||||||
getHeaderInfo();
|
getHeaderInfo();
|
||||||
@ -124,4 +126,8 @@ public class WavInfo {
|
|||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getFile() {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user