added LGPL library as completely separated link; changed from mp3agic to

jaudiotagger;
This commit is contained in:
Harrison Deng 2018-07-20 15:24:49 -05:00
parent 810db62c18
commit 0da840b691
5 changed files with 108 additions and 38 deletions

View File

@ -5,6 +5,7 @@ buildscript {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://dl.bintray.com/ijabz/maven/" }
jcenter() jcenter()
google() google()
} }
@ -82,7 +83,6 @@ project(":core") {
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.github.rwl:jtransforms:2.4.0" compile "com.github.rwl:jtransforms:2.4.0"
compile "org.apache.commons:commons-math3:3.2" compile "org.apache.commons:commons-math3:3.2"
compile group: 'com.mpatric', name: 'mp3agic', version: '0.9.1'
} }
} }

Binary file not shown.

Binary file not shown.

BIN
core/lib/jaudiotagger-2.2.3.jar Executable file

Binary file not shown.

View File

@ -1,6 +1,27 @@
package zero1hd.rhythmbullet.audio; package zero1hd.rhythmbullet.audio;
import java.io.IOException; 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.Gdx;
import com.badlogic.gdx.files.FileHandle; 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.graphics.Texture;
import com.badlogic.gdx.utils.Base64Coder; import com.badlogic.gdx.utils.Base64Coder;
import com.badlogic.gdx.utils.Json; 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 { public class MP3Metadata implements AudioMetadata {
private String title;
private String author; private String author;
private String length; private String length;
private String genre; private String genre;
@ -22,51 +39,95 @@ public class MP3Metadata implements AudioMetadata {
private FileHandle fileHandle; private FileHandle fileHandle;
private RhythmBulletMetadata rbMetadata; private RhythmBulletMetadata rbMetadata;
private Json json; private Json json;
public MP3Metadata() { private boolean id3v24;
public MP3Metadata(FileHandle fileHandle) {
this.fileHandle = fileHandle;
json = new Json(); json = new Json();
try { try {
Mp3File mp3file = new Mp3File(fileHandle.file()); MP3File mp3file = (MP3File) AudioFileIO.read(fileHandle.file());
long lenInSec = mp3file.getLengthInSeconds(); 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); int min = (int) (lenInSec/60);
length = (lenInSec/60) + ":" + (lenInSec - (min*60)); length = (lenInSec/60) + ":" + (lenInSec - (min*60));
if (mp3file.hasId3v1Tag()) { author = tag.getFirst(ID3v23FieldKey.ARTIST);
ID3v1 tag = mp3file.getId3v1Tag(); genre = tag.getFirst(ID3v23FieldKey.GENRE);
author = tag.getArtist(); title = tag.getFirst(ID3v23FieldKey.TITLE);
genre = tag.getGenreDescription();
if (tag.hasFrame("TXXX")) {
ID3v23Frame frame = null;
if (tag.getFrame("TXXX") instanceof List) {
@SuppressWarnings("unchecked")
List<ID3v23Frame> list = (List<ID3v23Frame>) 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 {
if (mp3file.hasCustomTag()) { frame = (ID3v23Frame) tag.getFrame("TXXX");
rbMetadata = json.fromJson(RhythmBulletMetadata.class, new String(Base64Coder.decode(new String(mp3file.getCustomTag())))); }
FrameBodyTXXX txxx = (FrameBodyTXXX) frame.getBody();
rbMetadata = json.fromJson(RhythmBulletMetadata.class, new String(Base64Coder.decode(txxx.getText())));
} else { } else {
rbMetadata = new RhythmBulletMetadata(); 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) { } catch (IOException e) {
Gdx.app.debug("MP3Metadata", "IO error while reading metadata."); 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 @Override
public void loadAlbumCover() { public void loadAlbumCover() {
MP3File mp3file;
try { try {
Mp3File mp3file = new Mp3File(fileHandle.file()); mp3file = (MP3File) AudioFileIO.read(fileHandle.file());
if (mp3file.hasId3v2Tag()) {
byte[] imageData = mp3file.getId3v2Tag().getAlbumImage(); if (mp3file.hasID3v2Tag()) {
byte[] imageData = mp3file.getID3v2Tag().getFirstArtwork().getBinaryData();
Pixmap pixmap = new Pixmap(imageData, 0, imageData.length); Pixmap pixmap = new Pixmap(imageData, 0, imageData.length);
albumCover = new Texture(pixmap); albumCover = new Texture(pixmap);
pixmap.dispose(); 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(); e.printStackTrace();
} }
} }
@Override @Override
@ -107,20 +168,29 @@ public class MP3Metadata implements AudioMetadata {
@Override @Override
public boolean flushRBMetadata() { public boolean flushRBMetadata() {
MP3File mp3file;
try { try {
Mp3File mp3file = new Mp3File(fileHandle.file()); mp3file = (MP3File) AudioFileIO.read(fileHandle.file());
mp3file.setCustomTag(Base64Coder.encodeString(json.toJson(rbMetadata)).getBytes()); } catch (CannotReadException | IOException | TagException | ReadOnlyFileException
String tempName = "." + fileHandle.name() + ".tmp"; | InvalidAudioFrameException e1) {
mp3file.save(tempName); e1.printStackTrace();
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) {
return false; 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 @Override