decided on not using custom tag due to limitations of formatting;
completed (untested) both wav and mp3 metadata objects.
This commit is contained in:
parent
0da840b691
commit
7782a6a44b
@ -27,6 +27,12 @@ public interface AudioMetadata extends Disposable {
|
||||
*/
|
||||
public String getAuthor();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the title of the song in the metadata.
|
||||
*/
|
||||
public String getTitle();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the length of the song with proper fomatting.
|
||||
@ -51,19 +57,6 @@ public interface AudioMetadata extends Disposable {
|
||||
*/
|
||||
public FileHandle getFileHandle();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the extra metadata for RhythmBullet.
|
||||
*/
|
||||
public RhythmBulletMetadata getRBMetadata();
|
||||
|
||||
/**
|
||||
* This method effectively overwrites the mp3 file by creating a copy of it with the new metadata, and the deleting the old one, and renaming the new on to the old ones name.
|
||||
* This is the suggested way of doing things by the library author in this thread: https://github.com/mpatric/mp3agic/issues/69
|
||||
* @return true if succeeded in overwrite, and false if failed.
|
||||
*/
|
||||
public boolean flushRBMetadata();
|
||||
|
||||
@Override
|
||||
public void dispose();
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package zero1hd.rhythmbullet.audio;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
import org.jaudiotagger.audio.exceptions.CannotReadException;
|
||||
@ -9,41 +8,23 @@ 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;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
|
||||
public class MP3Metadata implements AudioMetadata {
|
||||
private String title;
|
||||
private String author;
|
||||
private String length;
|
||||
private String genre;
|
||||
private String title, author, length, genre;
|
||||
private Texture albumCover;
|
||||
private FileHandle fileHandle;
|
||||
private RhythmBulletMetadata rbMetadata;
|
||||
private Json json;
|
||||
private boolean id3v24;
|
||||
|
||||
public MP3Metadata(FileHandle fileHandle) {
|
||||
this.fileHandle = fileHandle;
|
||||
|
||||
json = new Json();
|
||||
try {
|
||||
MP3File mp3file = (MP3File) AudioFileIO.read(fileHandle.file());
|
||||
ID3v23Tag tag;
|
||||
@ -65,43 +46,8 @@ public class MP3Metadata implements AudioMetadata {
|
||||
genre = tag.getFirst(ID3v23FieldKey.GENRE);
|
||||
title = tag.getFirst(ID3v23FieldKey.TITLE);
|
||||
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
|
||||
} 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();
|
||||
} catch (IOException | CannotWriteException | CannotReadException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
Gdx.app.error("MP3Metadata", "Failed to read metadata of file: " + fileHandle.name());
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,29 +57,22 @@ public class MP3Metadata implements AudioMetadata {
|
||||
try {
|
||||
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 (CannotReadException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TagException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ReadOnlyFileException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidAudioFrameException e) {
|
||||
byte[] imageData = mp3file.getTag().getFirstArtwork().getBinaryData();
|
||||
Pixmap pixmap = new Pixmap(imageData, 0, imageData.length);
|
||||
albumCover = new Texture(pixmap);
|
||||
pixmap.dispose();
|
||||
|
||||
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadAlbumCover() {
|
||||
albumCover.dispose();
|
||||
albumCover = null;
|
||||
if (albumCover != null) {
|
||||
albumCover.dispose();
|
||||
albumCover = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,6 +80,11 @@ public class MP3Metadata implements AudioMetadata {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLength() {
|
||||
return length;
|
||||
@ -161,45 +105,10 @@ public class MP3Metadata implements AudioMetadata {
|
||||
return fileHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RhythmBulletMetadata getRBMetadata() {
|
||||
return rbMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean flushRBMetadata() {
|
||||
MP3File mp3file;
|
||||
try {
|
||||
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
|
||||
public void dispose() {
|
||||
if (albumCover != null) {
|
||||
albumCover.dispose();
|
||||
albumCover = null;
|
||||
|
||||
}
|
||||
unloadAlbumCover();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,73 +1,94 @@
|
||||
package zero1hd.rhythmbullet.audio;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
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.tag.FieldKey;
|
||||
import org.jaudiotagger.tag.Tag;
|
||||
import org.jaudiotagger.tag.TagException;
|
||||
|
||||
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.Json;
|
||||
|
||||
public class WAVMetadata implements AudioMetadata {
|
||||
private String author, length, genre;
|
||||
private RhythmBulletMetadata rbMetadata;
|
||||
private String title, author, length, genre;
|
||||
private Texture albumCover;
|
||||
private FileHandle fileHandle;
|
||||
private Json json;
|
||||
|
||||
public WAVMetadata(FileHandle fileHandle) {
|
||||
this.fileHandle = fileHandle;
|
||||
|
||||
try {
|
||||
AudioFile wav = AudioFileIO.read(fileHandle.file());
|
||||
int lenInSec = wav.getAudioHeader().getTrackLength();
|
||||
int min = (int) (lenInSec/60);
|
||||
this.length = (lenInSec/60) + ":" + (lenInSec - (min*60));
|
||||
|
||||
Tag tag = wav.getTag();
|
||||
title = tag.getFirst(FieldKey.TITLE);
|
||||
author = tag.getFirst(FieldKey.ARTIST);
|
||||
genre = tag.getFirst(FieldKey.GENRE);
|
||||
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
Gdx.app.error("WAVMetadata", "Failed to read metadata of file: " + fileHandle.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAlbumCover() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
AudioFile wav = AudioFileIO.read(fileHandle.file());
|
||||
|
||||
byte[] imageData = wav.getTag().getFirstArtwork().getBinaryData();
|
||||
Pixmap pixmap = new Pixmap(imageData, 0, imageData.length);
|
||||
albumCover = new Texture(pixmap);
|
||||
pixmap.dispose();
|
||||
|
||||
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadAlbumCover() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if (albumCover != null) {
|
||||
albumCover.dispose();
|
||||
albumCover = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return author;
|
||||
}
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLength() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Texture getAlbumCover() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return albumCover;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGenre() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return genre;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileHandle getFileHandle() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return fileHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RhythmBulletMetadata getRBMetadata() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean flushRBMetadata() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
unloadAlbumCover();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user