Java Code Examples for com.google.android.exoplayer2.metadata.Metadata#Entry

The following examples show how to use com.google.android.exoplayer2.metadata.Metadata#Entry . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GaplessInfoHolder.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the holder with data parsed from ID3 {@link Metadata}.
 *
 * @param metadata The metadata from which to parse the gapless information.
 * @return Whether the holder was populated.
 */
public boolean setFromMetadata(Metadata metadata) {
  for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry entry = metadata.get(i);
    if (entry instanceof CommentFrame) {
      CommentFrame commentFrame = (CommentFrame) entry;
      if (GAPLESS_DESCRIPTION.equals(commentFrame.description)
          && setFromComment(commentFrame.text)) {
        return true;
      }
    } else if (entry instanceof InternalFrame) {
      InternalFrame internalFrame = (InternalFrame) entry;
      if (GAPLESS_DOMAIN.equals(internalFrame.domain)
          && GAPLESS_DESCRIPTION.equals(internalFrame.description)
          && setFromComment(internalFrame.text)) {
        return true;
      }
    }
  }
  return false;
}
 
Example 2
Source File: AtomParsers.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static Metadata parseIlst(ParsableByteArray ilst, int limit) {
  ilst.skipBytes(Atom.HEADER_SIZE);
  ArrayList<Metadata.Entry> entries = new ArrayList<>();
  while (ilst.getPosition() < limit) {
    Metadata.Entry entry = MetadataUtil.parseIlstElement(ilst);
    if (entry != null) {
      entries.add(entry);
    }
  }
  return entries.isEmpty() ? null : new Metadata(entries);
}
 
Example 3
Source File: EventLogger.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
private void printMetadata(Metadata metadata, String prefix) {
  for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry entry = metadata.get(i);
    if (entry instanceof TextInformationFrame) {
      TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
      Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id,
          textInformationFrame.value));
    } else if (entry instanceof UrlLinkFrame) {
      UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
      Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
    } else if (entry instanceof PrivFrame) {
      PrivFrame privFrame = (PrivFrame) entry;
      Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
    } else if (entry instanceof GeobFrame) {
      GeobFrame geobFrame = (GeobFrame) entry;
      Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s",
          geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
    } else if (entry instanceof ApicFrame) {
      ApicFrame apicFrame = (ApicFrame) entry;
      Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s",
          apicFrame.id, apicFrame.mimeType, apicFrame.description));
    } else if (entry instanceof CommentFrame) {
      CommentFrame commentFrame = (CommentFrame) entry;
      Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id,
          commentFrame.language, commentFrame.description));
    } else if (entry instanceof Id3Frame) {
      Id3Frame id3Frame = (Id3Frame) entry;
      Log.d(TAG, prefix + String.format("%s", id3Frame.id));
    } else if (entry instanceof EventMessage) {
      EventMessage eventMessage = (EventMessage) entry;
      Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s",
          eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
    }
  }
}
 
Example 4
Source File: EventLogger.java    From TubiPlayer with MIT License 5 votes vote down vote up
private void printMetadata(Metadata metadata, String prefix) {
    for (int i = 0; i < metadata.length(); i++) {
        Metadata.Entry entry = metadata.get(i);
        if (entry instanceof TextInformationFrame) {
            TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
            Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id,
                    textInformationFrame.value));
        } else if (entry instanceof UrlLinkFrame) {
            UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
            Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
        } else if (entry instanceof PrivFrame) {
            PrivFrame privFrame = (PrivFrame) entry;
            Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
        } else if (entry instanceof GeobFrame) {
            GeobFrame geobFrame = (GeobFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s",
                    geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
        } else if (entry instanceof ApicFrame) {
            ApicFrame apicFrame = (ApicFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s",
                    apicFrame.id, apicFrame.mimeType, apicFrame.description));
        } else if (entry instanceof CommentFrame) {
            CommentFrame commentFrame = (CommentFrame) entry;
            Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id,
                    commentFrame.language, commentFrame.description));
        } else if (entry instanceof Id3Frame) {
            Id3Frame id3Frame = (Id3Frame) entry;
            Log.d(TAG, prefix + String.format("%s", id3Frame.id));
        } else if (entry instanceof EventMessage) {
            EventMessage eventMessage = (EventMessage) entry;
            Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s",
                    eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
        }
    }
}
 
Example 5
Source File: GaplessInfoHolder.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Populates the holder with data parsed from ID3 {@link Metadata}.
 *
 * @param metadata The metadata from which to parse the gapless information.
 * @return Whether the holder was populated.
 */
public boolean setFromMetadata(Metadata metadata) {
  for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry entry = metadata.get(i);
    if (entry instanceof CommentFrame) {
      CommentFrame commentFrame = (CommentFrame) entry;
      if (setFromComment(commentFrame.description, commentFrame.text)) {
        return true;
      }
    }
  }
  return false;
}
 
Example 6
Source File: AtomParsers.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static Metadata parseIlst(ParsableByteArray ilst, int limit) {
  ilst.skipBytes(Atom.HEADER_SIZE);
  ArrayList<Metadata.Entry> entries = new ArrayList<>();
  while (ilst.getPosition() < limit) {
    Metadata.Entry entry = MetadataUtil.parseIlstElement(ilst);
    if (entry != null) {
      entries.add(entry);
    }
  }
  return entries.isEmpty() ? null : new Metadata(entries);
}
 
Example 7
Source File: EventLogger.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
private void printMetadata(Metadata metadata, String prefix) {
  for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry entry = metadata.get(i);
    if (entry instanceof TextInformationFrame) {
      TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
      Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id,
          textInformationFrame.value));
    } else if (entry instanceof UrlLinkFrame) {
      UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
      Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
    } else if (entry instanceof PrivFrame) {
      PrivFrame privFrame = (PrivFrame) entry;
      Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
    } else if (entry instanceof GeobFrame) {
      GeobFrame geobFrame = (GeobFrame) entry;
      Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s",
          geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
    } else if (entry instanceof ApicFrame) {
      ApicFrame apicFrame = (ApicFrame) entry;
      Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s",
          apicFrame.id, apicFrame.mimeType, apicFrame.description));
    } else if (entry instanceof CommentFrame) {
      CommentFrame commentFrame = (CommentFrame) entry;
      Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id,
          commentFrame.language, commentFrame.description));
    } else if (entry instanceof Id3Frame) {
      Id3Frame id3Frame = (Id3Frame) entry;
      Log.d(TAG, prefix + String.format("%s", id3Frame.id));
    } else if (entry instanceof EventMessage) {
      EventMessage eventMessage = (EventMessage) entry;
      Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s",
          eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
    }
  }
}
 
Example 8
Source File: EventLogger.java    From TigerVideo with Apache License 2.0 5 votes vote down vote up
private void printMetadata(Metadata metadata, String prefix) {
    for (int i = 0; i < metadata.length(); i++) {
        Metadata.Entry entry = metadata.get(i);
        if (entry instanceof TextInformationFrame) {
            TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
            Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id,
                    textInformationFrame.value));
        } else if (entry instanceof UrlLinkFrame) {
            UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
            Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
        } else if (entry instanceof PrivFrame) {
            PrivFrame privFrame = (PrivFrame) entry;
            Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
        } else if (entry instanceof GeobFrame) {
            GeobFrame geobFrame = (GeobFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s",
                    geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
        } else if (entry instanceof ApicFrame) {
            ApicFrame apicFrame = (ApicFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s",
                    apicFrame.id, apicFrame.mimeType, apicFrame.description));
        } else if (entry instanceof CommentFrame) {
            CommentFrame commentFrame = (CommentFrame) entry;
            Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id,
                    commentFrame.language, commentFrame.description));
        } else if (entry instanceof Id3Frame) {
            Id3Frame id3Frame = (Id3Frame) entry;
            Log.d(TAG, prefix + String.format("%s", id3Frame.id));
        } else if (entry instanceof EventMessage) {
            EventMessage eventMessage = (EventMessage) entry;
            Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s",
                    eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
        }
    }
}
 
Example 9
Source File: SimpleExoPlayerView.java    From K-Sonic with MIT License 5 votes vote down vote up
private boolean setArtworkFromMetadata(Metadata metadata) {
  for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry metadataEntry = metadata.get(i);
    if (metadataEntry instanceof ApicFrame) {
      byte[] bitmapData = ((ApicFrame) metadataEntry).pictureData;
      Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
      return setArtworkFromBitmap(bitmap);
    }
  }
  return false;
}
 
Example 10
Source File: EventLogger.java    From LiveVideoBroadcaster with Apache License 2.0 5 votes vote down vote up
private void printMetadata(Metadata metadata, String prefix) {
  for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry entry = metadata.get(i);
    if (entry instanceof TextInformationFrame) {
      TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
      Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id,
          textInformationFrame.value));
    } else if (entry instanceof UrlLinkFrame) {
      UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
      Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
    } else if (entry instanceof PrivFrame) {
      PrivFrame privFrame = (PrivFrame) entry;
      Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
    } else if (entry instanceof GeobFrame) {
      GeobFrame geobFrame = (GeobFrame) entry;
      Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s",
          geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
    } else if (entry instanceof ApicFrame) {
      ApicFrame apicFrame = (ApicFrame) entry;
      Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s",
          apicFrame.id, apicFrame.mimeType, apicFrame.description));
    } else if (entry instanceof CommentFrame) {
      CommentFrame commentFrame = (CommentFrame) entry;
      Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id,
          commentFrame.language, commentFrame.description));
    } else if (entry instanceof Id3Frame) {
      Id3Frame id3Frame = (Id3Frame) entry;
      Log.d(TAG, prefix + String.format("%s", id3Frame.id));
    } else if (entry instanceof EventMessage) {
      EventMessage eventMessage = (EventMessage) entry;
      Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s",
          eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
    }
  }
}
 
Example 11
Source File: CustomizePlayerView.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private boolean setArtworkFromMetadata(Metadata metadata) {
    for (int i = 0; i < metadata.length(); i++) {
        Metadata.Entry metadataEntry = metadata.get(i);
        if (metadataEntry instanceof ApicFrame) {
            byte[] bitmapData = ((ApicFrame) metadataEntry).pictureData;
            Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
            return setArtworkFromBitmap(bitmap);
        }
    }
    return false;
}
 
Example 12
Source File: EventLogger.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
private void printMetadata(Metadata metadata, String prefix) {
    for (int i = 0; i < metadata.length(); i++) {
        Metadata.Entry entry = metadata.get(i);
        if (entry instanceof TextInformationFrame) {
            TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
            Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id,
                    textInformationFrame.value));
        } else if (entry instanceof UrlLinkFrame) {
            UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
            Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
        } else if (entry instanceof PrivFrame) {
            PrivFrame privFrame = (PrivFrame) entry;
            Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
        } else if (entry instanceof GeobFrame) {
            GeobFrame geobFrame = (GeobFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s",
                    geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
        } else if (entry instanceof ApicFrame) {
            ApicFrame apicFrame = (ApicFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s",
                    apicFrame.id, apicFrame.mimeType, apicFrame.description));
        } else if (entry instanceof CommentFrame) {
            CommentFrame commentFrame = (CommentFrame) entry;
            Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id,
                    commentFrame.language, commentFrame.description));
        } else if (entry instanceof Id3Frame) {
            Id3Frame id3Frame = (Id3Frame) entry;
            Log.d(TAG, prefix + String.format("%s", id3Frame.id));
        } else if (entry instanceof EventMessage) {
            EventMessage eventMessage = (EventMessage) entry;
            Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s",
                    eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
        }
    }
}
 
Example 13
Source File: DefaultHlsExtractorFactory.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** Returns true if this {@code format} represents a 'variant' track (i.e. the main one). */
private static boolean isFmp4Variant(Format format) {
  Metadata metadata = format.metadata;
  if (metadata == null) {
    return false;
  }
  for (int i = 0; i < metadata.length(); i++) {
    Metadata.Entry entry = metadata.get(i);
    if (entry instanceof HlsTrackMetadataEntry) {
      return !((HlsTrackMetadataEntry) entry).variantInfos.isEmpty();
    }
  }
  return false;
}
 
Example 14
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Strips the private timestamp frame from metadata, if present. See:
 * https://github.com/google/ExoPlayer/issues/5063
 */
@Nullable
private Metadata getAdjustedMetadata(@Nullable Metadata metadata) {
  if (metadata == null) {
    return null;
  }
  int length = metadata.length();
  int transportStreamTimestampMetadataIndex = C.INDEX_UNSET;
  for (int i = 0; i < length; i++) {
    Metadata.Entry metadataEntry = metadata.get(i);
    if (metadataEntry instanceof PrivFrame) {
      PrivFrame privFrame = (PrivFrame) metadataEntry;
      if (HlsMediaChunk.PRIV_TIMESTAMP_FRAME_OWNER.equals(privFrame.owner)) {
        transportStreamTimestampMetadataIndex = i;
        break;
      }
    }
  }
  if (transportStreamTimestampMetadataIndex == C.INDEX_UNSET) {
    return metadata;
  }
  if (length == 1) {
    return null;
  }
  Metadata.Entry[] newMetadataEntries = new Metadata.Entry[length - 1];
  for (int i = 0; i < length; i++) {
    if (i != transportStreamTimestampMetadataIndex) {
      int newIndex = i < transportStreamTimestampMetadataIndex ? i : i - 1;
      newMetadataEntries[newIndex] = metadata.get(i);
    }
  }
  return new Metadata(newMetadataEntries);
}
 
Example 15
Source File: Mp3Extractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Nullable
private static MlltSeeker maybeHandleSeekMetadata(Metadata metadata, long firstFramePosition) {
  if (metadata != null) {
    int length = metadata.length();
    for (int i = 0; i < length; i++) {
      Metadata.Entry entry = metadata.get(i);
      if (entry instanceof MlltFrame) {
        return MlltSeeker.create(firstFramePosition, (MlltFrame) entry);
      }
    }
  }
  return null;
}
 
Example 16
Source File: EventLogger.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
private void printMetadata(Metadata metadata, String prefix) {
    for (int i = 0; i < metadata.length(); i++) {
        Metadata.Entry entry = metadata.get(i);
        if (entry instanceof TextInformationFrame) {
            TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
            Log.d(TAG, prefix + String.format("%s: value=%s", textInformationFrame.id,
                    textInformationFrame.value));
        } else if (entry instanceof UrlLinkFrame) {
            UrlLinkFrame urlLinkFrame = (UrlLinkFrame) entry;
            Log.d(TAG, prefix + String.format("%s: url=%s", urlLinkFrame.id, urlLinkFrame.url));
        } else if (entry instanceof PrivFrame) {
            PrivFrame privFrame = (PrivFrame) entry;
            Log.d(TAG, prefix + String.format("%s: owner=%s", privFrame.id, privFrame.owner));
        } else if (entry instanceof GeobFrame) {
            GeobFrame geobFrame = (GeobFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, filename=%s, description=%s",
                    geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
        } else if (entry instanceof ApicFrame) {
            ApicFrame apicFrame = (ApicFrame) entry;
            Log.d(TAG, prefix + String.format("%s: mimeType=%s, description=%s",
                    apicFrame.id, apicFrame.mimeType, apicFrame.description));
        } else if (entry instanceof CommentFrame) {
            CommentFrame commentFrame = (CommentFrame) entry;
            Log.d(TAG, prefix + String.format("%s: language=%s, description=%s", commentFrame.id,
                    commentFrame.language, commentFrame.description));
        } else if (entry instanceof Id3Frame) {
            Id3Frame id3Frame = (Id3Frame) entry;
            Log.d(TAG, prefix + String.format("%s", id3Frame.id));
        } else if (entry instanceof EventMessage) {
            EventMessage eventMessage = (EventMessage) entry;
            Log.d(TAG, prefix + String.format("EMSG: scheme=%s, id=%d, value=%s",
                    eventMessage.schemeIdUri, eventMessage.id, eventMessage.value));
        }
    }
}
 
Example 17
Source File: ExoVideoView.java    From ExoVideoView with Apache License 2.0 5 votes vote down vote up
private boolean setArtworkFromMetadata(Metadata metadata) {
    for (int i = 0; i < metadata.length(); i++) {
        Metadata.Entry metadataEntry = metadata.get(i);
        if (metadataEntry instanceof ApicFrame) {
            byte[] bitmapData = ((ApicFrame) metadataEntry).pictureData;
            Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
            return setArtworkFromBitmap(bitmap);
        }
    }
    return false;
}
 
Example 18
Source File: AtomParsers.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Parses a metadata meta atom if it contains metadata with handler 'mdta'.
 *
 * @param meta The metadata atom to decode.
 * @return Parsed metadata, or null.
 */
@Nullable
public static Metadata parseMdtaFromMeta(Atom.ContainerAtom meta) {
  Atom.LeafAtom hdlrAtom = meta.getLeafAtomOfType(Atom.TYPE_hdlr);
  Atom.LeafAtom keysAtom = meta.getLeafAtomOfType(Atom.TYPE_keys);
  Atom.LeafAtom ilstAtom = meta.getLeafAtomOfType(Atom.TYPE_ilst);
  if (hdlrAtom == null
      || keysAtom == null
      || ilstAtom == null
      || AtomParsers.parseHdlr(hdlrAtom.data) != TYPE_mdta) {
    // There isn't enough information to parse the metadata, or the handler type is unexpected.
    return null;
  }

  // Parse metadata keys.
  ParsableByteArray keys = keysAtom.data;
  keys.setPosition(Atom.FULL_HEADER_SIZE);
  int entryCount = keys.readInt();
  String[] keyNames = new String[entryCount];
  for (int i = 0; i < entryCount; i++) {
    int entrySize = keys.readInt();
    keys.skipBytes(4); // keyNamespace
    int keySize = entrySize - 8;
    keyNames[i] = keys.readString(keySize);
  }

  // Parse metadata items.
  ParsableByteArray ilst = ilstAtom.data;
  ilst.setPosition(Atom.HEADER_SIZE);
  ArrayList<Metadata.Entry> entries = new ArrayList<>();
  while (ilst.bytesLeft() > Atom.HEADER_SIZE) {
    int atomPosition = ilst.getPosition();
    int atomSize = ilst.readInt();
    int keyIndex = ilst.readInt() - 1;
    if (keyIndex >= 0 && keyIndex < keyNames.length) {
      String key = keyNames[keyIndex];
      Metadata.Entry entry =
          MetadataUtil.parseMdtaMetadataEntryFromIlst(ilst, atomPosition + atomSize, key);
      if (entry != null) {
        entries.add(entry);
      }
    } else {
      Log.w(TAG, "Skipped metadata with unknown key index: " + keyIndex);
    }
    ilst.setPosition(atomPosition + atomSize);
  }
  return entries.isEmpty() ? null : new Metadata(entries);
}
 
Example 19
Source File: MetadataUtil.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a single ilst element from a {@link ParsableByteArray}. The element is read starting
 * from the current position of the {@link ParsableByteArray}, and the position is advanced by the
 * size of the element. The position is advanced even if the element's type is unrecognized.
 *
 * @param ilst Holds the data to be parsed.
 * @return The parsed element, or null if the element's type was not recognized.
 */
public static @Nullable Metadata.Entry parseIlstElement(ParsableByteArray ilst) {
  int position = ilst.getPosition();
  int endPosition = position + ilst.readInt();
  int type = ilst.readInt();
  int typeTopByte = (type >> 24) & 0xFF;
  try {
    if (typeTopByte == '\u00A9' /* Copyright char */
        || typeTopByte == '\uFFFD' /* Replacement char */) {
      int shortType = type & 0x00FFFFFF;
      if (shortType == SHORT_TYPE_COMMENT) {
        return parseCommentAttribute(type, ilst);
      } else if (shortType == SHORT_TYPE_NAME_1 || shortType == SHORT_TYPE_NAME_2) {
        return parseTextAttribute(type, "TIT2", ilst);
      } else if (shortType == SHORT_TYPE_COMPOSER_1 || shortType == SHORT_TYPE_COMPOSER_2) {
        return parseTextAttribute(type, "TCOM", ilst);
      } else if (shortType == SHORT_TYPE_YEAR) {
        return parseTextAttribute(type, "TDRC", ilst);
      } else if (shortType == SHORT_TYPE_ARTIST) {
        return parseTextAttribute(type, "TPE1", ilst);
      } else if (shortType == SHORT_TYPE_ENCODER) {
        return parseTextAttribute(type, "TSSE", ilst);
      } else if (shortType == SHORT_TYPE_ALBUM) {
        return parseTextAttribute(type, "TALB", ilst);
      } else if (shortType == SHORT_TYPE_LYRICS) {
        return parseTextAttribute(type, "USLT", ilst);
      } else if (shortType == SHORT_TYPE_GENRE) {
        return parseTextAttribute(type, "TCON", ilst);
      } else if (shortType == TYPE_GROUPING) {
        return parseTextAttribute(type, "TIT1", ilst);
      }
    } else if (type == TYPE_GENRE) {
      return parseStandardGenreAttribute(ilst);
    } else if (type == TYPE_DISK_NUMBER) {
      return parseIndexAndCountAttribute(type, "TPOS", ilst);
    } else if (type == TYPE_TRACK_NUMBER) {
      return parseIndexAndCountAttribute(type, "TRCK", ilst);
    } else if (type == TYPE_TEMPO) {
      return parseUint8Attribute(type, "TBPM", ilst, true, false);
    } else if (type == TYPE_COMPILATION) {
      return parseUint8Attribute(type, "TCMP", ilst, true, true);
    } else if (type == TYPE_COVER_ART) {
      return parseCoverArt(ilst);
    } else if (type == TYPE_ALBUM_ARTIST) {
      return parseTextAttribute(type, "TPE2", ilst);
    } else if (type == TYPE_SORT_TRACK_NAME) {
      return parseTextAttribute(type, "TSOT", ilst);
    } else if (type == TYPE_SORT_ALBUM) {
      return parseTextAttribute(type, "TSO2", ilst);
    } else if (type == TYPE_SORT_ARTIST) {
      return parseTextAttribute(type, "TSOA", ilst);
    } else if (type == TYPE_SORT_ALBUM_ARTIST) {
      return parseTextAttribute(type, "TSOP", ilst);
    } else if (type == TYPE_SORT_COMPOSER) {
      return parseTextAttribute(type, "TSOC", ilst);
    } else if (type == TYPE_RATING) {
      return parseUint8Attribute(type, "ITUNESADVISORY", ilst, false, false);
    } else if (type == TYPE_GAPLESS_ALBUM) {
      return parseUint8Attribute(type, "ITUNESGAPLESS", ilst, false, true);
    } else if (type == TYPE_TV_SORT_SHOW) {
      return parseTextAttribute(type, "TVSHOWSORT", ilst);
    } else if (type == TYPE_TV_SHOW) {
      return parseTextAttribute(type, "TVSHOW", ilst);
    } else if (type == TYPE_INTERNAL) {
      return parseInternalAttribute(ilst, endPosition);
    }
    Log.d(TAG, "Skipped unknown metadata entry: " + Atom.getAtomTypeString(type));
    return null;
  } finally {
    ilst.setPosition(endPosition);
  }
}
 
Example 20
Source File: MetadataUtil.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Parses a single userdata ilst element from a {@link ParsableByteArray}. The element is read
 * starting from the current position of the {@link ParsableByteArray}, and the position is
 * advanced by the size of the element. The position is advanced even if the element's type is
 * unrecognized.
 *
 * @param ilst Holds the data to be parsed.
 * @return The parsed element, or null if the element's type was not recognized.
 */
@Nullable
public static Metadata.Entry parseIlstElement(ParsableByteArray ilst) {
  int position = ilst.getPosition();
  int endPosition = position + ilst.readInt();
  int type = ilst.readInt();
  int typeTopByte = (type >> 24) & 0xFF;
  try {
    if (typeTopByte == TYPE_TOP_BYTE_COPYRIGHT || typeTopByte == TYPE_TOP_BYTE_REPLACEMENT) {
      int shortType = type & 0x00FFFFFF;
      if (shortType == SHORT_TYPE_COMMENT) {
        return parseCommentAttribute(type, ilst);
      } else if (shortType == SHORT_TYPE_NAME_1 || shortType == SHORT_TYPE_NAME_2) {
        return parseTextAttribute(type, "TIT2", ilst);
      } else if (shortType == SHORT_TYPE_COMPOSER_1 || shortType == SHORT_TYPE_COMPOSER_2) {
        return parseTextAttribute(type, "TCOM", ilst);
      } else if (shortType == SHORT_TYPE_YEAR) {
        return parseTextAttribute(type, "TDRC", ilst);
      } else if (shortType == SHORT_TYPE_ARTIST) {
        return parseTextAttribute(type, "TPE1", ilst);
      } else if (shortType == SHORT_TYPE_ENCODER) {
        return parseTextAttribute(type, "TSSE", ilst);
      } else if (shortType == SHORT_TYPE_ALBUM) {
        return parseTextAttribute(type, "TALB", ilst);
      } else if (shortType == SHORT_TYPE_LYRICS) {
        return parseTextAttribute(type, "USLT", ilst);
      } else if (shortType == SHORT_TYPE_GENRE) {
        return parseTextAttribute(type, "TCON", ilst);
      } else if (shortType == TYPE_GROUPING) {
        return parseTextAttribute(type, "TIT1", ilst);
      }
    } else if (type == TYPE_GENRE) {
      return parseStandardGenreAttribute(ilst);
    } else if (type == TYPE_DISK_NUMBER) {
      return parseIndexAndCountAttribute(type, "TPOS", ilst);
    } else if (type == TYPE_TRACK_NUMBER) {
      return parseIndexAndCountAttribute(type, "TRCK", ilst);
    } else if (type == TYPE_TEMPO) {
      return parseUint8Attribute(type, "TBPM", ilst, true, false);
    } else if (type == TYPE_COMPILATION) {
      return parseUint8Attribute(type, "TCMP", ilst, true, true);
    } else if (type == TYPE_COVER_ART) {
      return parseCoverArt(ilst);
    } else if (type == TYPE_ALBUM_ARTIST) {
      return parseTextAttribute(type, "TPE2", ilst);
    } else if (type == TYPE_SORT_TRACK_NAME) {
      return parseTextAttribute(type, "TSOT", ilst);
    } else if (type == TYPE_SORT_ALBUM) {
      return parseTextAttribute(type, "TSO2", ilst);
    } else if (type == TYPE_SORT_ARTIST) {
      return parseTextAttribute(type, "TSOA", ilst);
    } else if (type == TYPE_SORT_ALBUM_ARTIST) {
      return parseTextAttribute(type, "TSOP", ilst);
    } else if (type == TYPE_SORT_COMPOSER) {
      return parseTextAttribute(type, "TSOC", ilst);
    } else if (type == TYPE_RATING) {
      return parseUint8Attribute(type, "ITUNESADVISORY", ilst, false, false);
    } else if (type == TYPE_GAPLESS_ALBUM) {
      return parseUint8Attribute(type, "ITUNESGAPLESS", ilst, false, true);
    } else if (type == TYPE_TV_SORT_SHOW) {
      return parseTextAttribute(type, "TVSHOWSORT", ilst);
    } else if (type == TYPE_TV_SHOW) {
      return parseTextAttribute(type, "TVSHOW", ilst);
    } else if (type == TYPE_INTERNAL) {
      return parseInternalAttribute(ilst, endPosition);
    }
    Log.d(TAG, "Skipped unknown metadata entry: " + Atom.getAtomTypeString(type));
    return null;
  } finally {
    ilst.setPosition(endPosition);
  }
}