completed proper save mechanism for custom metadata

This commit is contained in:
Harrison Deng 2018-07-08 20:50:08 -05:00
parent 466f1cfc3e
commit 02a65651ea
3 changed files with 15 additions and 5 deletions

View File

@ -22,7 +22,7 @@ public interface AudioMetadata extends Disposable {
public RhythmBulletMetadata getRBMetadata(); public RhythmBulletMetadata getRBMetadata();
public void flushRBMetadata(); public boolean flushRBMetadata();
@Override @Override
public void dispose(); public void dispose();

View File

@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.Json;
import com.mpatric.mp3agic.ID3v1; import com.mpatric.mp3agic.ID3v1;
import com.mpatric.mp3agic.InvalidDataException; import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.Mp3File; import com.mpatric.mp3agic.Mp3File;
import com.mpatric.mp3agic.NotSupportedException;
import com.mpatric.mp3agic.UnsupportedTagException; import com.mpatric.mp3agic.UnsupportedTagException;
public class MP3Metadata implements AudioMetadata { public class MP3Metadata implements AudioMetadata {
@ -105,12 +106,21 @@ public class MP3Metadata implements AudioMetadata {
} }
@Override @Override
public void flushRBMetadata() { public boolean flushRBMetadata() {
try { try {
Mp3File mp3file = new Mp3File(fileHandle.file()); Mp3File mp3file = new Mp3File(fileHandle.file());
mp3file.setCustomTag(Base64Coder.encodeString(json.toJson(rbMetadata)).getBytes()); mp3file.setCustomTag(Base64Coder.encodeString(json.toJson(rbMetadata)).getBytes());
} catch (UnsupportedTagException | InvalidDataException | IOException e) { 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) {
e.printStackTrace(); e.printStackTrace();
return false;
} }
} }

View File

@ -60,9 +60,9 @@ public class WAVMetadata implements AudioMetadata {
} }
@Override @Override
public void flushRBMetadata() { public boolean flushRBMetadata() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false;
} }
@Override @Override