From f57602788ee2219fbe7ec7e2e8261a0acfd8b371 Mon Sep 17 00:00:00 2001 From: Recrown Date: Wed, 3 May 2017 18:28:55 -0500 Subject: [PATCH] music selection ui layout changed --- build.gradle | 6 +- .../polyjet/ui/builders/MusicSelectable.java | 80 +++++++++++++++---- .../polyjet/ui/builders/ScrollText.java | 8 +- core/src/zero1hd/wavedecoder/WavInfo.java | 6 ++ 4 files changed, 80 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index b8133b3..a6a7627 100755 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ project(":desktop") { 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.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.mpatric:mp3agic:0.9.0" + compile "org:jaudiotagger:2.0.3" } } diff --git a/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java b/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java index 836cc4d..be78548 100755 --- a/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java +++ b/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java @@ -2,6 +2,15 @@ package zero1hd.polyjet.ui.builders; 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.Preferences; 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.Label; 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.mpatric.mp3agic.ID3v2; -import com.mpatric.mp3agic.InvalidDataException; -import com.mpatric.mp3agic.Mp3File; -import com.mpatric.mp3agic.UnsupportedTagException; import zero1hd.wavedecoder.WavInfo; @@ -26,6 +33,7 @@ public class MusicSelectable extends Button implements Disposable { private String songName; private Texture albumCover; WavInfo wavinfo; + private String author; private int previousTop; private int ratedDifficulty; private byte[] albumWorkBytes; @@ -33,6 +41,9 @@ public class MusicSelectable extends Button implements Disposable { private Image imageIcon; private ScrollText displayName; private Label runTime; + private Label authorLabel; + private Label previousTopLabel; + private Label ratedDifficultyLabel; private Skin skin; public MusicSelectable(FileHandle musicFile, Preferences musicData, final Skin skin, Texture defaultAlbumC) { super(skin, "info-button"); @@ -41,23 +52,36 @@ public class MusicSelectable extends Button implements Disposable { this.albumCover = defaultAlbumC; if (musicFile.extension().toLowerCase().equals("mp3")) { + MP3File mp3File; try { - Mp3File mp3File = new Mp3File(musicFile.file()); - durationInSeconds = mp3File.getLengthInSeconds(); + mp3File = new MP3File(musicFile.file()); + durationInSeconds = mp3File.getAudioHeader().getTrackLength(); - if (mp3File.hasId3v2Tag()) { - ID3v2 id3v2tag = mp3File.getId3v2Tag(); - albumWorkBytes = id3v2tag.getAlbumImage(); - - songName = id3v2tag.getTitle(); + if (mp3File.getTag() != null) { + albumWorkBytes = mp3File.getTag().getFirstArtwork().getBinaryData(); } - } catch (UnsupportedTagException | InvalidDataException | IOException e) { - Gdx.app.debug("Music Selector", "Error while reading tag for " + musicFile.name()); + + songName = mp3File.getTag().getFirst(FieldKey.TITLE); + author = mp3File.getTag().getFirst(FieldKey.ARTIST); + } catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } + } else { wavinfo = new WavInfo(musicFile.file()); 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) { invalidMusic = true; @@ -69,23 +93,47 @@ public class MusicSelectable extends Button implements Disposable { previousTop = musicData.getInteger(songName + ":previous top"); ratedDifficulty = musicData.getInteger(songName + ":difficulty"); + + if (author == null || author.isEmpty()) { + author = "N/A"; + } } public void addInfoToPanel() { displayName = new ScrollText(songName, skin, true); - add(displayName).fillX().spaceBottom(20f); + defaults().align(Align.top); + + add(displayName).fillX().padTop(15f).top(); row(); String formattedTime = "Run time: "+ String.valueOf(durationInSeconds/60) + ":"; if (durationInSeconds - (durationInSeconds/60)*60 < 10) { formattedTime = formattedTime.concat("0"); } + + Table songInfoTable = new Table(); + formattedTime = formattedTime.concat(String.valueOf(durationInSeconds - (durationInSeconds/60)*60)); 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(); 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); } - add(imageIcon); + add(imageIcon).size(246f); } public int getPreviousTop() { diff --git a/core/src/zero1hd/polyjet/ui/builders/ScrollText.java b/core/src/zero1hd/polyjet/ui/builders/ScrollText.java index f7edfd1..f1ad146 100755 --- a/core/src/zero1hd/polyjet/ui/builders/ScrollText.java +++ b/core/src/zero1hd/polyjet/ui/builders/ScrollText.java @@ -51,6 +51,12 @@ public class ScrollText extends Widget { currentlyHovering = false; 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 public void act(float delta) { if (scrollOnHover) { - if (currentlyHovering) { + if ((int) textOffset != 0 || currentlyHovering) { if (textOffset < -fontWidth) { textOffset = clipBounds.getWidth(); } diff --git a/core/src/zero1hd/wavedecoder/WavInfo.java b/core/src/zero1hd/wavedecoder/WavInfo.java index 4a84c5e..70640f0 100755 --- a/core/src/zero1hd/wavedecoder/WavInfo.java +++ b/core/src/zero1hd/wavedecoder/WavInfo.java @@ -15,9 +15,11 @@ public class WavInfo { private DataInputStream readStream; private String fileName; + private File file; public WavInfo(File file) throws InvalidParameterException { try { fileName = file.getName(); + this.file = file; audioFile = new FileInputStream(file); initDataStream(); getHeaderInfo(); @@ -124,4 +126,8 @@ public class WavInfo { public String getFileName() { return fileName; } + + public File getFile() { + return file; + } }