mp3 metadata complete
This commit is contained in:
parent
31bc3eb273
commit
2588b1e4a3
@ -46,7 +46,6 @@ project(":desktop") {
|
|||||||
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
|
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
|
||||||
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||||
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
|
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +69,6 @@ project(":android") {
|
|||||||
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
|
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
|
||||||
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
|
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
|
||||||
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
|
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +82,7 @@ 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'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,29 +4,28 @@ import com.badlogic.gdx.files.FileHandle;
|
|||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
public class AudioMetadata implements Disposable {
|
public interface AudioMetadata extends Disposable {
|
||||||
private String author;
|
|
||||||
private String length;
|
|
||||||
private Texture albumCover;
|
|
||||||
private String lastPlayed;
|
|
||||||
private FileHandle fileHandle;
|
|
||||||
|
|
||||||
public AudioMetadata(FileHandle fileHandle) {
|
public void loadAlbumCover();
|
||||||
this.fileHandle = fileHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadAlbumCover() {
|
public void unloadAlbumCover();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unloadAlbumCover() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public String getAuthor();
|
||||||
|
|
||||||
|
public String getLength();
|
||||||
|
|
||||||
|
public Texture getAlbumCover();
|
||||||
|
|
||||||
|
public String getLastPlayed();
|
||||||
|
|
||||||
|
public String getGenre();
|
||||||
|
|
||||||
|
public FileHandle getFileHandle();
|
||||||
|
|
||||||
|
public RhythmBulletMetadata getRBMetadata();
|
||||||
|
|
||||||
|
public void flushRBMetadata();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose();
|
||||||
// TODO Auto-generated method stub
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
132
core/src/zero1hd/rhythmbullet/audio/MP3Metadata.java
Executable file
132
core/src/zero1hd/rhythmbullet/audio/MP3Metadata.java
Executable file
@ -0,0 +1,132 @@
|
|||||||
|
package zero1hd.rhythmbullet.audio;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
|
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.UnsupportedTagException;
|
||||||
|
|
||||||
|
public class MP3Metadata implements AudioMetadata {
|
||||||
|
private String author = "N/A";
|
||||||
|
private String length;
|
||||||
|
private String genre;
|
||||||
|
private String lastPlayed;
|
||||||
|
private Texture albumCover;
|
||||||
|
private FileHandle fileHandle;
|
||||||
|
private RhythmBulletMetadata rbMetadata;
|
||||||
|
private Json json;
|
||||||
|
public MP3Metadata() {
|
||||||
|
json = new Json();
|
||||||
|
try {
|
||||||
|
Mp3File mp3file = new Mp3File(fileHandle.file());
|
||||||
|
long lenInSec = mp3file.getLengthInSeconds();
|
||||||
|
int min = (int) (lenInSec/60);
|
||||||
|
length = (lenInSec/60) + ":" + (lenInSec - (min*60));
|
||||||
|
|
||||||
|
if (mp3file.hasId3v1Tag()) {
|
||||||
|
ID3v1 tag = mp3file.getId3v1Tag();
|
||||||
|
author = tag.getArtist();
|
||||||
|
genre = tag.getGenreDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (mp3file.hasCustomTag()) {
|
||||||
|
rbMetadata = json.fromJson(RhythmBulletMetadata.class, new String(Base64Coder.decode(new String(mp3file.getCustomTag()))));
|
||||||
|
} 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadAlbumCover() {
|
||||||
|
try {
|
||||||
|
Mp3File mp3file = new Mp3File(fileHandle.file());
|
||||||
|
if (mp3file.hasId3v2Tag()) {
|
||||||
|
byte[] imageData = mp3file.getId3v2Tag().getAlbumImage();
|
||||||
|
Pixmap pixmap = new Pixmap(imageData, 0, imageData.length);
|
||||||
|
albumCover = new Texture(pixmap);
|
||||||
|
pixmap.dispose();
|
||||||
|
}
|
||||||
|
} catch (UnsupportedTagException | InvalidDataException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unloadAlbumCover() {
|
||||||
|
albumCover.dispose();
|
||||||
|
albumCover = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGenre() {
|
||||||
|
return genre;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Texture getAlbumCover() {
|
||||||
|
return albumCover;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLastPlayed() {
|
||||||
|
return lastPlayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileHandle getFileHandle() {
|
||||||
|
return fileHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RhythmBulletMetadata getRBMetadata() {
|
||||||
|
return rbMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flushRBMetadata() {
|
||||||
|
try {
|
||||||
|
Mp3File mp3file = new Mp3File(fileHandle.file());
|
||||||
|
mp3file.setCustomTag(Base64Coder.encodeString(json.toJson(rbMetadata)).getBytes());
|
||||||
|
} catch (UnsupportedTagException | InvalidDataException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
if (albumCover != null) {
|
||||||
|
albumCover.dispose();
|
||||||
|
albumCover = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
core/src/zero1hd/rhythmbullet/audio/RhythmBulletMetadata.java
Executable file
29
core/src/zero1hd/rhythmbullet/audio/RhythmBulletMetadata.java
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
package zero1hd.rhythmbullet.audio;
|
||||||
|
|
||||||
|
public class RhythmBulletMetadata {
|
||||||
|
private String highScore = "0", lastPlayed = "N/A", difficulty = "N/A";
|
||||||
|
|
||||||
|
public void setHighScore(String highScore) {
|
||||||
|
this.highScore = highScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastPlayed(String lastPlayed) {
|
||||||
|
this.lastPlayed = lastPlayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDifficulty(String difficulty) {
|
||||||
|
this.difficulty = difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHighScore() {
|
||||||
|
return highScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDifficulty() {
|
||||||
|
return difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastPlayed() {
|
||||||
|
return lastPlayed;
|
||||||
|
}
|
||||||
|
}
|
@ -1,49 +0,0 @@
|
|||||||
package zero1hd.rhythmbullet.util;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
|
||||||
import com.badlogic.gdx.utils.Base64Coder;
|
|
||||||
import com.badlogic.gdx.utils.Json;
|
|
||||||
|
|
||||||
public class Base64Preferences {
|
|
||||||
FileHandle base64File;
|
|
||||||
HashMap<String, String> prefKeys;
|
|
||||||
Json json;
|
|
||||||
|
|
||||||
public Base64Preferences(String prefName) {
|
|
||||||
base64File = Gdx.files.external(".prefs/.priv/" + prefName);
|
|
||||||
json = new Json();
|
|
||||||
|
|
||||||
flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putString(String key, String string) {
|
|
||||||
prefKeys.put(key, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putObj(String key, Object object) {
|
|
||||||
prefKeys.put(key, json.toJson(object));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeBase64String(String text) {
|
|
||||||
base64File.writeString(Base64Coder.encodeString(text), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeBase64Object(Object obj) {
|
|
||||||
base64File.writeString(Base64Coder.encodeString(json.toJson(obj)), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void flush() {
|
|
||||||
prefKeys = json.fromJson(HashMap.class, new String(Base64Coder.decode(base64File.readString())));
|
|
||||||
if (prefKeys == null) {
|
|
||||||
prefKeys = new HashMap<>();
|
|
||||||
}
|
|
||||||
base64File.writeString(null, false);
|
|
||||||
writeBase64Object(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.Array;
|
|||||||
import com.badlogic.gdx.utils.Sort;
|
import com.badlogic.gdx.utils.Sort;
|
||||||
|
|
||||||
import zero1hd.rhythmbullet.audio.MusicManager;
|
import zero1hd.rhythmbullet.audio.MusicManager;
|
||||||
|
import zero1hd.rhythmbullet.desktop.audio.processor.MP3AudioProcessor;
|
||||||
|
|
||||||
public class MusicList extends Observable {
|
public class MusicList extends Observable {
|
||||||
private Array<FileHandle> musicArray;
|
private Array<FileHandle> musicArray;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package zero1hd.rhythmbullet.desktop.audio;
|
package zero1hd.rhythmbullet.desktop.audio.processor;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
Loading…
x
Reference in New Issue
Block a user