Commit 9597ecbb by OxygenCobalt

Clean up VorbisUtil

Try to eliminate some nitpicks regarding VorbisUtil.
parent 0ea8567b
...@@ -269,7 +269,7 @@ public final class FlacStreamMetadata { ...@@ -269,7 +269,7 @@ public final class FlacStreamMetadata {
@Nullable @Nullable
Metadata appendedMetadata = Metadata appendedMetadata =
getMetadataCopyWithAppendedEntriesFrom( getMetadataCopyWithAppendedEntriesFrom(
VorbisUtil.buildMetadata(vorbisComments, Collections.emptyList())); VorbisUtil.buildMetadata(vorbisComments));
return new FlacStreamMetadata( return new FlacStreamMetadata(
minBlockSizeSamples, minBlockSizeSamples,
maxBlockSizeSamples, maxBlockSizeSamples,
......
...@@ -270,7 +270,8 @@ public final class VorbisUtil { ...@@ -270,7 +270,8 @@ public final class VorbisUtil {
* All others will be transformed into vorbis comments. * All others will be transformed into vorbis comments.
* *
* @param vorbisComments The raw input of comments, as a key-value pair KEY=VAL. * @param vorbisComments The raw input of comments, as a key-value pair KEY=VAL.
* @return A metadata instance containing the processed tags. * @return A Metadata instance containing the parsed metadata entries. Null if there are no
* valid metadata entries that can be parsed.
*/ */
@Nullable @Nullable
public static Metadata buildMetadata(List<String> vorbisComments) { public static Metadata buildMetadata(List<String> vorbisComments) {
...@@ -285,7 +286,8 @@ public final class VorbisUtil { ...@@ -285,7 +286,8 @@ public final class VorbisUtil {
* *
* @param vorbisComments The raw input of comments, as a key-value pair KEY=VAL. * @param vorbisComments The raw input of comments, as a key-value pair KEY=VAL.
* @param pictureFrames Any picture frames that were parsed beforehand. * @param pictureFrames Any picture frames that were parsed beforehand.
* @return A metadata instance containing the processed tags. * @return A Metadata instance containing the parsed metadata entries. Null if there are no
* valid metadata entries that can be parsed.
*/ */
@Nullable @Nullable
public static Metadata buildMetadata(List<String> vorbisComments, List<PictureFrame> pictureFrames) { public static Metadata buildMetadata(List<String> vorbisComments, List<PictureFrame> pictureFrames) {
...@@ -300,21 +302,22 @@ public final class VorbisUtil { ...@@ -300,21 +302,22 @@ public final class VorbisUtil {
if (keyAndValue.length != 2) { if (keyAndValue.length != 2) {
Log.w(TAG, "Failed to parse Vorbis comment: " + vorbisComment); Log.w(TAG, "Failed to parse Vorbis comment: " + vorbisComment);
} else { continue;
if (keyAndValue[0].equals("METADATA_BLOCK_PICTURE")) { }
// This tag is a special cover art tag, outlined by
// https://wiki.xiph.org/index.php/VorbisComment#Cover_art. if (keyAndValue[0].equals("METADATA_BLOCK_PICTURE")) {
// Decode it from Base64 and transform it into a PictureFrame. // This tag is a special cover art tag, outlined by
try { // https://wiki.xiph.org/index.php/VorbisComment#Cover_art.
byte[] decoded = Base64.decode(keyAndValue[1], Base64.DEFAULT); // Decode it from Base64 and transform it into a PictureFrame.
metadataEntries.add(buildPictureFrame(new ParsableByteArray(decoded))); try {
} catch (Exception e) { byte[] decoded = Base64.decode(keyAndValue[1], Base64.DEFAULT);
Log.w(TAG, "Failed to parse vorbis picture"); metadataEntries.add(buildPictureFrame(new ParsableByteArray(decoded)));
} } catch (Exception e) {
} else { Log.w(TAG, "Failed to parse vorbis picture");
VorbisComment entry = new VorbisComment(keyAndValue[0], keyAndValue[1]);
metadataEntries.add(entry);
} }
} else {
VorbisComment entry = new VorbisComment(keyAndValue[0], keyAndValue[1]);
metadataEntries.add(entry);
} }
} }
metadataEntries.addAll(pictureFrames); metadataEntries.addAll(pictureFrames);
...@@ -328,7 +331,7 @@ public final class VorbisUtil { ...@@ -328,7 +331,7 @@ public final class VorbisUtil {
* @param scratch The bytes of the picture. * @param scratch The bytes of the picture.
* @return A picture frame from the scratch data. * @return A picture frame from the scratch data.
*/ */
static PictureFrame buildPictureFrame(ParsableByteArray scratch) { public static PictureFrame buildPictureFrame(ParsableByteArray scratch) {
int pictureType = scratch.readInt(); int pictureType = scratch.readInt();
int mimeTypeLength = scratch.readInt(); int mimeTypeLength = scratch.readInt();
String mimeType = scratch.readString(mimeTypeLength, Charsets.US_ASCII); String mimeType = scratch.readString(mimeTypeLength, Charsets.US_ASCII);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment