mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Clean up VorbisUtil
Try to eliminate some nitpicks regarding VorbisUtil.
This commit is contained in:
parent
0ea8567b6b
commit
9597ecbb31
2 changed files with 21 additions and 18 deletions
|
|
@ -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 {
|
||||||
* 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 {
|
||||||
*
|
*
|
||||||
* @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 {
|
||||||
|
|
||||||
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 {
|
||||||
* @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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue