diff --git a/build.gradle b/build.gradle index 5e5c43c..bf528ec 100755 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ buildscript { mavenLocal() mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } + maven { url "https://dl.bintray.com/ijabz/maven/" } jcenter() google() } @@ -82,7 +83,6 @@ project(":core") { compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" compile "com.github.rwl:jtransforms:2.4.0" compile "org.apache.commons:commons-math3:3.2" - compile group: 'com.mpatric', name: 'mp3agic', version: '0.9.1' } } diff --git a/core/lib/jaudiotagger-2.2.3-javadoc.jar b/core/lib/jaudiotagger-2.2.3-javadoc.jar new file mode 100755 index 0000000..122f5ae Binary files /dev/null and b/core/lib/jaudiotagger-2.2.3-javadoc.jar differ diff --git a/core/lib/jaudiotagger-2.2.3-sources.jar b/core/lib/jaudiotagger-2.2.3-sources.jar new file mode 100755 index 0000000..31d7173 Binary files /dev/null and b/core/lib/jaudiotagger-2.2.3-sources.jar differ diff --git a/core/lib/jaudiotagger-2.2.3.jar b/core/lib/jaudiotagger-2.2.3.jar new file mode 100755 index 0000000..7069a3b Binary files /dev/null and b/core/lib/jaudiotagger-2.2.3.jar differ diff --git a/core/src/zero1hd/rhythmbullet/audio/MP3Metadata.java b/core/src/zero1hd/rhythmbullet/audio/MP3Metadata.java index 1d7616e..8bc07b5 100755 --- a/core/src/zero1hd/rhythmbullet/audio/MP3Metadata.java +++ b/core/src/zero1hd/rhythmbullet/audio/MP3Metadata.java @@ -1,6 +1,27 @@ package zero1hd.rhythmbullet.audio; import java.io.IOException; +import java.util.List; + +import org.jaudiotagger.audio.AudioFileIO; +import org.jaudiotagger.audio.exceptions.CannotReadException; +import org.jaudiotagger.audio.exceptions.CannotWriteException; +import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; +import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; +import org.jaudiotagger.audio.mp3.MP3File; +import org.jaudiotagger.tag.FieldDataInvalidException; +import org.jaudiotagger.tag.FieldKey; +import org.jaudiotagger.tag.Tag; +import org.jaudiotagger.tag.TagException; +import org.jaudiotagger.tag.TagOptionSingleton; +import org.jaudiotagger.tag.id3.AbstractID3v2Frame; +import org.jaudiotagger.tag.id3.AbstractID3v2Tag; +import org.jaudiotagger.tag.id3.ID3v23FieldKey; +import org.jaudiotagger.tag.id3.ID3v23Frame; +import org.jaudiotagger.tag.id3.ID3v23Tag; +import org.jaudiotagger.tag.id3.ID3v24FieldKey; +import org.jaudiotagger.tag.id3.ID3v24Tag; +import org.jaudiotagger.tag.id3.framebody.FrameBodyTXXX; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; @@ -8,13 +29,9 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.utils.Base64Coder; import com.badlogic.gdx.utils.Json; -import com.mpatric.mp3agic.ID3v1; -import com.mpatric.mp3agic.InvalidDataException; -import com.mpatric.mp3agic.Mp3File; -import com.mpatric.mp3agic.NotSupportedException; -import com.mpatric.mp3agic.UnsupportedTagException; public class MP3Metadata implements AudioMetadata { + private String title; private String author; private String length; private String genre; @@ -22,51 +39,95 @@ public class MP3Metadata implements AudioMetadata { private FileHandle fileHandle; private RhythmBulletMetadata rbMetadata; private Json json; - public MP3Metadata() { + private boolean id3v24; + public MP3Metadata(FileHandle fileHandle) { + this.fileHandle = fileHandle; + json = new Json(); try { - Mp3File mp3file = new Mp3File(fileHandle.file()); - long lenInSec = mp3file.getLengthInSeconds(); + MP3File mp3file = (MP3File) AudioFileIO.read(fileHandle.file()); + ID3v23Tag tag; + if (mp3file.hasID3v1Tag()) { + mp3file.setID3v2Tag(mp3file.getID3v1Tag()); + mp3file.setID3v1Tag(null); + mp3file.commit(); + tag = (ID3v23Tag) mp3file.getTagAndConvertOrCreateAndSetDefault(); + } + tag = (ID3v23Tag) mp3file.getTagAndConvertOrCreateAndSetDefault(); + + + + int lenInSec = mp3file.getAudioHeader().getTrackLength(); int min = (int) (lenInSec/60); length = (lenInSec/60) + ":" + (lenInSec - (min*60)); - if (mp3file.hasId3v1Tag()) { - ID3v1 tag = mp3file.getId3v1Tag(); - author = tag.getArtist(); - genre = tag.getGenreDescription(); - } + author = tag.getFirst(ID3v23FieldKey.ARTIST); + genre = tag.getFirst(ID3v23FieldKey.GENRE); + title = tag.getFirst(ID3v23FieldKey.TITLE); - - if (mp3file.hasCustomTag()) { - rbMetadata = json.fromJson(RhythmBulletMetadata.class, new String(Base64Coder.decode(new String(mp3file.getCustomTag())))); + if (tag.hasFrame("TXXX")) { + ID3v23Frame frame = null; + if (tag.getFrame("TXXX") instanceof List) { + @SuppressWarnings("unchecked") + List list = (List) tag.getFrame("TXXX"); + for (int i = 0; i < list.size(); i++) { + if (((FrameBodyTXXX) list.get(i).getBody()).getDescription().equals("RBMD")) { + frame = list.get(i); + break; + } + } + } else { + frame = (ID3v23Frame) tag.getFrame("TXXX"); + } + FrameBodyTXXX txxx = (FrameBodyTXXX) frame.getBody(); + rbMetadata = json.fromJson(RhythmBulletMetadata.class, new String(Base64Coder.decode(txxx.getText()))); } else { rbMetadata = new RhythmBulletMetadata(); - mp3file.setCustomTag(Base64Coder.encodeString(json.toJson(rbMetadata)).getBytes()); } - } catch (UnsupportedTagException e) { - Gdx.app.debug("MP3Metadata", "Tag not supported by MP3agic."); - } catch (InvalidDataException e) { - Gdx.app.debug("MP3Metadata", "This files metadata has errors."); } catch (IOException e) { Gdx.app.debug("MP3Metadata", "IO error while reading metadata."); + } catch (CannotReadException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TagException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ReadOnlyFileException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvalidAudioFrameException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CannotWriteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } } @Override public void loadAlbumCover() { + MP3File mp3file; try { - Mp3File mp3file = new Mp3File(fileHandle.file()); - if (mp3file.hasId3v2Tag()) { - byte[] imageData = mp3file.getId3v2Tag().getAlbumImage(); + mp3file = (MP3File) AudioFileIO.read(fileHandle.file()); + + if (mp3file.hasID3v2Tag()) { + byte[] imageData = mp3file.getID3v2Tag().getFirstArtwork().getBinaryData(); Pixmap pixmap = new Pixmap(imageData, 0, imageData.length); albumCover = new Texture(pixmap); pixmap.dispose(); } - } catch (UnsupportedTagException | InvalidDataException | IOException e) { + } catch (CannotReadException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (TagException e) { + e.printStackTrace(); + } catch (ReadOnlyFileException e) { + e.printStackTrace(); + } catch (InvalidAudioFrameException e) { e.printStackTrace(); } - } @Override @@ -107,20 +168,29 @@ public class MP3Metadata implements AudioMetadata { @Override public boolean flushRBMetadata() { + MP3File mp3file; try { - Mp3File mp3file = new Mp3File(fileHandle.file()); - mp3file.setCustomTag(Base64Coder.encodeString(json.toJson(rbMetadata)).getBytes()); - String tempName = "." + fileHandle.name() + ".tmp"; - mp3file.save(tempName); - String path = fileHandle.path(); - path.substring(0, path.length() - path.indexOf(tempName)); - path += tempName; - fileHandle.delete(); - fileHandle = Gdx.files.absolute(path); - return true; - } catch (UnsupportedTagException | InvalidDataException | IOException | NotSupportedException e) { + mp3file = (MP3File) AudioFileIO.read(fileHandle.file()); + } catch (CannotReadException | IOException | TagException | ReadOnlyFileException + | InvalidAudioFrameException e1) { + e1.printStackTrace(); return false; } + + ID3v23Tag tag = (ID3v23Tag) mp3file.getID3v2Tag(); + + ID3v23Frame frame = new ID3v23Frame("TXXX"); + FrameBodyTXXX txxxBody = new FrameBodyTXXX(); + frame.setBody(txxxBody); + txxxBody.setDescription("RBMD");; + txxxBody.setText(Base64Coder.encodeString(json.toJson(rbMetadata))); + try { + tag.setField(frame); + } catch (FieldDataInvalidException e) { + e.printStackTrace(); + return false; + } + return true; } @Override