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

The following examples show how to use com.google.android.exoplayer2.metadata.Metadata. These examples are extracted from open source projects. 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 Project: MediaSDK   Source File: AtomParsers.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses a udta atom.
 *
 * @param udtaAtom The udta (user data) atom to decode.
 * @param isQuickTime True for QuickTime media. False otherwise.
 * @return Parsed metadata, or null.
 */
@Nullable
public static Metadata parseUdta(Atom.LeafAtom udtaAtom, boolean isQuickTime) {
  if (isQuickTime) {
    // Meta boxes are regular boxes rather than full boxes in QuickTime. For now, don't try and
    // decode one.
    return null;
  }
  ParsableByteArray udtaData = udtaAtom.data;
  udtaData.setPosition(Atom.HEADER_SIZE);
  while (udtaData.bytesLeft() >= Atom.HEADER_SIZE) {
    int atomPosition = udtaData.getPosition();
    int atomSize = udtaData.readInt();
    int atomType = udtaData.readInt();
    if (atomType == Atom.TYPE_meta) {
      udtaData.setPosition(atomPosition);
      return parseUdtaMeta(udtaData, atomPosition + atomSize);
    }
    udtaData.setPosition(atomPosition + atomSize);
  }
  return null;
}
 
Example 2
Source Project: MediaSDK   Source File: IcyDecoder.java    License: Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
/* package */ Metadata decode(String metadata) {
  @Nullable String name = null;
  @Nullable String url = null;
  int index = 0;
  Matcher matcher = METADATA_ELEMENT.matcher(metadata);
  while (matcher.find(index)) {
    String key = Util.toLowerInvariant(matcher.group(1));
    String value = matcher.group(2);
    switch (key) {
      case STREAM_KEY_NAME:
        name = value;
        break;
      case STREAM_KEY_URL:
        url = value;
        break;
    }
    index = matcher.end();
  }
  return new Metadata(new IcyInfo(metadata, name, url));
}
 
Example 3
Source Project: MediaSDK   Source File: FlacStreamMetadata.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static Metadata buildMetadata(
    List<String> vorbisComments, List<PictureFrame> pictureFrames) {
  if (vorbisComments.isEmpty() && pictureFrames.isEmpty()) {
    return null;
  }

  ArrayList<Metadata.Entry> metadataEntries = new ArrayList<>();
  for (int i = 0; i < vorbisComments.size(); i++) {
    String vorbisComment = vorbisComments.get(i);
    String[] keyAndValue = Util.splitAtFirst(vorbisComment, SEPARATOR);
    if (keyAndValue.length != 2) {
      Log.w(TAG, "Failed to parse vorbis comment: " + vorbisComment);
    } else {
      VorbisComment entry = new VorbisComment(keyAndValue[0], keyAndValue[1]);
      metadataEntries.add(entry);
    }
  }
  metadataEntries.addAll(pictureFrames);

  return metadataEntries.isEmpty() ? null : new Metadata(metadataEntries);
}
 
Example 4
Source Project: TelePlus-Android   Source File: AtomParsers.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a udta atom.
 *
 * @param udtaAtom The udta (user data) atom to decode.
 * @param isQuickTime True for QuickTime media. False otherwise.
 * @return Parsed metadata, or null.
 */
public static Metadata parseUdta(Atom.LeafAtom udtaAtom, boolean isQuickTime) {
  if (isQuickTime) {
    // Meta boxes are regular boxes rather than full boxes in QuickTime. For now, don't try and
    // decode one.
    return null;
  }
  ParsableByteArray udtaData = udtaAtom.data;
  udtaData.setPosition(Atom.HEADER_SIZE);
  while (udtaData.bytesLeft() >= Atom.HEADER_SIZE) {
    int atomPosition = udtaData.getPosition();
    int atomSize = udtaData.readInt();
    int atomType = udtaData.readInt();
    if (atomType == Atom.TYPE_meta) {
      udtaData.setPosition(atomPosition);
      return parseMetaAtom(udtaData, atomPosition + atomSize);
    }
    udtaData.skipBytes(atomSize - Atom.HEADER_SIZE);
  }
  return null;
}
 
Example 5
/**
 * 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 6
Source Project: TelePlus-Android   Source File: AtomParsers.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parses a udta atom.
 *
 * @param udtaAtom The udta (user data) atom to decode.
 * @param isQuickTime True for QuickTime media. False otherwise.
 * @return Parsed metadata, or null.
 */
public static Metadata parseUdta(Atom.LeafAtom udtaAtom, boolean isQuickTime) {
  if (isQuickTime) {
    // Meta boxes are regular boxes rather than full boxes in QuickTime. For now, don't try and
    // decode one.
    return null;
  }
  ParsableByteArray udtaData = udtaAtom.data;
  udtaData.setPosition(Atom.HEADER_SIZE);
  while (udtaData.bytesLeft() >= Atom.HEADER_SIZE) {
    int atomPosition = udtaData.getPosition();
    int atomSize = udtaData.readInt();
    int atomType = udtaData.readInt();
    if (atomType == Atom.TYPE_meta) {
      udtaData.setPosition(atomPosition);
      return parseMetaAtom(udtaData, atomPosition + atomSize);
    }
    udtaData.skipBytes(atomSize - Atom.HEADER_SIZE);
  }
  return null;
}
 
Example 7
Source Project: K-Sonic   Source File: AtomParsers.java    License: MIT License 6 votes vote down vote up
/**
 * Parses a udta atom.
 *
 * @param udtaAtom The udta (user data) atom to decode.
 * @param isQuickTime True for QuickTime media. False otherwise.
 * @return Parsed metadata, or null.
 */
public static Metadata parseUdta(Atom.LeafAtom udtaAtom, boolean isQuickTime) {
  if (isQuickTime) {
    // Meta boxes are regular boxes rather than full boxes in QuickTime. For now, don't try and
    // decode one.
    return null;
  }
  ParsableByteArray udtaData = udtaAtom.data;
  udtaData.setPosition(Atom.HEADER_SIZE);
  while (udtaData.bytesLeft() >= Atom.HEADER_SIZE) {
    int atomPosition = udtaData.getPosition();
    int atomSize = udtaData.readInt();
    int atomType = udtaData.readInt();
    if (atomType == Atom.TYPE_meta) {
      udtaData.setPosition(atomPosition);
      return parseMetaAtom(udtaData, atomPosition + atomSize);
    }
    udtaData.skipBytes(atomSize - Atom.HEADER_SIZE);
  }
  return null;
}
 
Example 8
/**
 * 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 9
Source Project: K-Sonic   Source File: SimpleExoPlayerView.java    License: 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 Project: MediaSDK   Source File: AtomParsers.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static Metadata parseUdtaMeta(ParsableByteArray meta, int limit) {
  meta.skipBytes(Atom.FULL_HEADER_SIZE);
  while (meta.getPosition() < limit) {
    int atomPosition = meta.getPosition();
    int atomSize = meta.readInt();
    int atomType = meta.readInt();
    if (atomType == Atom.TYPE_ilst) {
      meta.setPosition(atomPosition);
      return parseIlst(meta, atomPosition + atomSize);
    }
    meta.setPosition(atomPosition + atomSize);
  }
  return null;
}
 
Example 11
Source Project: MediaSDK   Source File: AtomParsers.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
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 12
Source Project: MediaSDK   Source File: MetadataUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link Format} that is the same as the input format but includes information from the
 * specified sources of metadata.
 */
public static Format getFormatWithMetadata(
    int trackType,
    Format format,
    @Nullable Metadata udtaMetadata,
    @Nullable Metadata mdtaMetadata,
    GaplessInfoHolder gaplessInfoHolder) {
  if (trackType == C.TRACK_TYPE_AUDIO) {
    if (gaplessInfoHolder.hasGaplessInfo()) {
      format =
          format.copyWithGaplessInfo(
              gaplessInfoHolder.encoderDelay, gaplessInfoHolder.encoderPadding);
    }
    // We assume all udta metadata is associated with the audio track.
    if (udtaMetadata != null) {
      format = format.copyWithMetadata(udtaMetadata);
    }
  } else if (trackType == C.TRACK_TYPE_VIDEO && mdtaMetadata != null) {
    // Populate only metadata keys that are known to be specific to video.
    for (int i = 0; i < mdtaMetadata.length(); i++) {
      Metadata.Entry entry = mdtaMetadata.get(i);
      if (entry instanceof MdtaMetadataEntry) {
        MdtaMetadataEntry mdtaMetadataEntry = (MdtaMetadataEntry) entry;
        if (MDTA_KEY_ANDROID_CAPTURE_FPS.equals(mdtaMetadataEntry.key)
            && mdtaMetadataEntry.typeIndicator == MDTA_TYPE_INDICATOR_FLOAT) {
          try {
            float fps = ByteBuffer.wrap(mdtaMetadataEntry.value).asFloatBuffer().get();
            format = format.copyWithFrameRate(fps);
            format = format.copyWithMetadata(new Metadata(mdtaMetadataEntry));
          } catch (NumberFormatException e) {
            Log.w(TAG, "Ignoring invalid framerate");
          }
        }
      }
    }
  }
  return format;
}
 
Example 13
Source Project: K-Sonic   Source File: SimpleExoPlayerView.java    License: MIT License 5 votes vote down vote up
private void updateForCurrentTrackSelections() {
  if (player == null) {
    return;
  }
  TrackSelectionArray selections = player.getCurrentTrackSelections();
  for (int i = 0; i < selections.length; i++) {
    if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
      // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
      // onRenderedFirstFrame().
      hideArtwork();
      return;
    }
  }
  // Video disabled so the shutter must be closed.
  if (shutterView != null) {
    shutterView.setVisibility(VISIBLE);
  }
  // Display artwork if enabled and available, else hide it.
  if (useArtwork) {
    for (int i = 0; i < selections.length; i++) {
      TrackSelection selection = selections.get(i);
      if (selection != null) {
        for (int j = 0; j < selection.length(); j++) {
          Metadata metadata = selection.getFormat(j).metadata;
          if (metadata != null && setArtworkFromMetadata(metadata)) {
            return;
          }
        }
      }
    }
    if (setArtworkFromBitmap(defaultArtwork)) {
      return;
    }
  }
  // Artwork disabled or unavailable.
  hideArtwork();
}
 
Example 14
Source Project: MediaSDK   Source File: Mp3Extractor.java    License: 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 15
Source Project: MediaSDK   Source File: Id3Peeker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Peeks ID3 data from the input and parses the first ID3 tag.
 *
 * @param input The {@link ExtractorInput} from which data should be peeked.
 * @param id3FramePredicate Determines which ID3 frames are decoded. May be null to decode all
 *     frames.
 * @return The first ID3 tag decoded into a {@link Metadata} object. May be null if ID3 tag is not
 *     present in the input.
 * @throws IOException If an error occurred peeking from the input.
 * @throws InterruptedException If the thread was interrupted.
 */
@Nullable
public Metadata peekId3Data(
    ExtractorInput input, @Nullable Id3Decoder.FramePredicate id3FramePredicate)
    throws IOException, InterruptedException {
  int peekedId3Bytes = 0;
  Metadata metadata = null;
  while (true) {
    try {
      input.peekFully(scratch.data, /* offset= */ 0, Id3Decoder.ID3_HEADER_LENGTH);
    } catch (EOFException e) {
      // If input has less than ID3_HEADER_LENGTH, ignore the rest.
      break;
    }
    scratch.setPosition(0);
    if (scratch.readUnsignedInt24() != Id3Decoder.ID3_TAG) {
      // Not an ID3 tag.
      break;
    }
    scratch.skipBytes(3); // Skip major version, minor version and flags.
    int framesLength = scratch.readSynchSafeInt();
    int tagLength = Id3Decoder.ID3_HEADER_LENGTH + framesLength;

    if (metadata == null) {
      byte[] id3Data = new byte[tagLength];
      System.arraycopy(scratch.data, 0, id3Data, 0, Id3Decoder.ID3_HEADER_LENGTH);
      input.peekFully(id3Data, Id3Decoder.ID3_HEADER_LENGTH, framesLength);

      metadata = new Id3Decoder(id3FramePredicate).decode(id3Data, tagLength);
    } else {
      input.advancePeekPosition(framesLength);
    }

    peekedId3Bytes += tagLength;
  }

  input.resetPeekPosition();
  input.advancePeekPosition(peekedId3Bytes);
  return metadata;
}
 
Example 16
Source Project: MediaSDK   Source File: AnalyticsCollector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final void onMetadata(Metadata metadata) {
  EventTime eventTime = generatePlayingMediaPeriodEventTime();
  for (AnalyticsListener listener : listeners) {
    listener.onMetadata(eventTime, metadata);
  }
}
 
Example 17
Source Project: MediaSDK   Source File: Id3Decoder.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ByteBufferBackingArray")
@Override
@Nullable
public Metadata decode(MetadataInputBuffer inputBuffer) {
  ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data);
  return decode(buffer.array(), buffer.limit());
}
 
Example 18
Source Project: MediaSDK   Source File: Id3Decoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Decodes ID3 tags.
 *
 * @param data The bytes to decode ID3 tags from.
 * @param size Amount of bytes in {@code data} to read.
 * @return A {@link Metadata} object containing the decoded ID3 tags, or null if the data could
 *     not be decoded.
 */
@Nullable
public Metadata decode(byte[] data, int size) {
  List<Id3Frame> id3Frames = new ArrayList<>();
  ParsableByteArray id3Data = new ParsableByteArray(data, size);

  Id3Header id3Header = decodeHeader(id3Data);
  if (id3Header == null) {
    return null;
  }

  int startPosition = id3Data.getPosition();
  int frameHeaderSize = id3Header.majorVersion == 2 ? 6 : 10;
  int framesSize = id3Header.framesSize;
  if (id3Header.isUnsynchronized) {
    framesSize = removeUnsynchronization(id3Data, id3Header.framesSize);
  }
  id3Data.setLimit(startPosition + framesSize);

  boolean unsignedIntFrameSizeHack = false;
  if (!validateFrames(id3Data, id3Header.majorVersion, frameHeaderSize, false)) {
    if (id3Header.majorVersion == 4 && validateFrames(id3Data, 4, frameHeaderSize, true)) {
      unsignedIntFrameSizeHack = true;
    } else {
      Log.w(TAG, "Failed to validate ID3 tag with majorVersion=" + id3Header.majorVersion);
      return null;
    }
  }

  while (id3Data.bytesLeft() >= frameHeaderSize) {
    Id3Frame frame = decodeFrame(id3Header.majorVersion, id3Data, unsignedIntFrameSizeHack,
        frameHeaderSize, framePredicate);
    if (frame != null) {
      id3Frames.add(frame);
    }
  }

  return new Metadata(id3Frames);
}
 
Example 19
Source Project: TigerVideo   Source File: EventLogger.java    License: 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 20
Source Project: MediaSDK   Source File: DefaultHlsExtractorFactory.java    License: 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 21
Source Project: MediaSDK   Source File: PlayerEmsgHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void parseAndDiscardSamples() {
  while (sampleQueue.isReady(/* loadingFinished= */ false)) {
    MetadataInputBuffer inputBuffer = dequeueSample();
    if (inputBuffer == null) {
      continue;
    }
    long eventTimeUs = inputBuffer.timeUs;
    Metadata metadata = decoder.decode(inputBuffer);
    EventMessage eventMessage = (EventMessage) metadata.get(0);
    if (isPlayerEmsgEvent(eventMessage.schemeIdUri, eventMessage.value)) {
      parsePlayerEmsgEvent(eventTimeUs, eventMessage);
    }
  }
  sampleQueue.discardToRead();
}
 
Example 22
Source Project: K-Sonic   Source File: Format.java    License: MIT License 5 votes vote down vote up
public static Format createAudioSampleFormat(String id, String sampleMimeType, String codecs,
    int bitrate, int maxInputSize, int channelCount, int sampleRate,
    @C.PcmEncoding int pcmEncoding, int encoderDelay, int encoderPadding,
    List<byte[]> initializationData, DrmInitData drmInitData,
    @C.SelectionFlags int selectionFlags, String language, Metadata metadata) {
  return new Format(id, null, sampleMimeType, codecs, bitrate, maxInputSize, NO_VALUE, NO_VALUE,
      NO_VALUE, NO_VALUE, NO_VALUE, null, NO_VALUE, channelCount, sampleRate, pcmEncoding,
      encoderDelay, encoderPadding, selectionFlags, language, NO_VALUE, OFFSET_SAMPLE_RELATIVE,
      initializationData, drmInitData, metadata);
}
 
Example 23
Source Project: ExoVideoView   Source File: ExoVideoView.java    License: Apache License 2.0 5 votes vote down vote up
private void updateForCurrentTrackSelections() {
    if (player == null) {
        return;
    }
    TrackSelectionArray selections = player.getCurrentTrackSelections();
    for (int i = 0; i < selections.length; i++) {
        if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
            // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
            // onRenderedFirstFrame().
            hideArtwork();
            return;
        }
    }
    // Video disabled so the shutter must be closed.
    if (shutterView != null) {
        shutterView.setVisibility(VISIBLE);
    }
    // Display artwork if enabled and available, else hide it.
    if (useArtwork) {
        for (int i = 0; i < selections.length; i++) {
            TrackSelection selection = selections.get(i);
            if (selection != null) {
                for (int j = 0; j < selection.length(); j++) {
                    Metadata metadata = selection.getFormat(j).metadata;
                    if (metadata != null && setArtworkFromMetadata(metadata)) {
                        return;
                    }
                }
            }
        }
        if (setArtworkFromBitmap(defaultArtwork)) {
            return;
        }
    }
    // Artwork disabled or unavailable.
    hideArtwork();
}
 
Example 24
Source Project: ExoPlayer-Offline   Source File: EventLogger.java    License: 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 25
Source Project: K-Sonic   Source File: Format.java    License: MIT License 5 votes vote down vote up
Format(String id, String containerMimeType, String sampleMimeType, String codecs,
    int bitrate, int maxInputSize, int width, int height, float frameRate, int rotationDegrees,
    float pixelWidthHeightRatio, byte[] projectionData, @C.StereoMode int stereoMode,
    int channelCount, int sampleRate, @C.PcmEncoding int pcmEncoding, int encoderDelay,
    int encoderPadding, @C.SelectionFlags int selectionFlags, String language,
    int accessibilityChannel, long subsampleOffsetUs, List<byte[]> initializationData,
    DrmInitData drmInitData, Metadata metadata) {
  this.id = id;
  this.containerMimeType = containerMimeType;
  this.sampleMimeType = sampleMimeType;
  this.codecs = codecs;
  this.bitrate = bitrate;
  this.maxInputSize = maxInputSize;
  this.width = width;
  this.height = height;
  this.frameRate = frameRate;
  this.rotationDegrees = rotationDegrees;
  this.pixelWidthHeightRatio = pixelWidthHeightRatio;
  this.projectionData = projectionData;
  this.stereoMode = stereoMode;
  this.channelCount = channelCount;
  this.sampleRate = sampleRate;
  this.pcmEncoding = pcmEncoding;
  this.encoderDelay = encoderDelay;
  this.encoderPadding = encoderPadding;
  this.selectionFlags = selectionFlags;
  this.language = language;
  this.accessibilityChannel = accessibilityChannel;
  this.subsampleOffsetUs = subsampleOffsetUs;
  this.initializationData = initializationData == null ? Collections.<byte[]>emptyList()
      : initializationData;
  this.drmInitData = drmInitData;
  this.metadata = metadata;
}
 
Example 26
Source Project: TelePlus-Android   Source File: AtomParsers.java    License: 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 27
Source Project: K-Sonic   Source File: Id3Decoder.java    License: MIT License 5 votes vote down vote up
/**
 * Decodes ID3 tags.
 *
 * @param data The bytes to decode ID3 tags from.
 * @param size Amount of bytes in {@code data} to read.
 * @return A {@link Metadata} object containing the decoded ID3 tags.
 */
public Metadata decode(byte[] data, int size) {
  List<Id3Frame> id3Frames = new ArrayList<>();
  ParsableByteArray id3Data = new ParsableByteArray(data, size);

  Id3Header id3Header = decodeHeader(id3Data);
  if (id3Header == null) {
    return null;
  }

  int startPosition = id3Data.getPosition();
  int framesSize = id3Header.framesSize;
  if (id3Header.isUnsynchronized) {
    framesSize = removeUnsynchronization(id3Data, id3Header.framesSize);
  }
  id3Data.setLimit(startPosition + framesSize);

  boolean unsignedIntFrameSizeHack = false;
  if (id3Header.majorVersion == 4) {
    if (!validateV4Frames(id3Data, false)) {
      if (validateV4Frames(id3Data, true)) {
        unsignedIntFrameSizeHack = true;
      } else {
        Log.w(TAG, "Failed to validate V4 ID3 tag");
        return null;
      }
    }
  }

  int frameHeaderSize = id3Header.majorVersion == 2 ? 6 : 10;
  while (id3Data.bytesLeft() >= frameHeaderSize) {
    Id3Frame frame = decodeFrame(id3Header.majorVersion, id3Data, unsignedIntFrameSizeHack,
        frameHeaderSize, framePredicate);
    if (frame != null) {
      id3Frames.add(frame);
    }
  }

  return new Metadata(id3Frames);
}
 
Example 28
Source Project: K-Sonic   Source File: AtomParsers.java    License: MIT License 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 29
Source Project: TelePlus-Android   Source File: Id3Decoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Decodes ID3 tags.
 *
 * @param data The bytes to decode ID3 tags from.
 * @param size Amount of bytes in {@code data} to read.
 * @return A {@link Metadata} object containing the decoded ID3 tags, or null if the data could
 *     not be decoded.
 */
public @Nullable Metadata decode(byte[] data, int size) {
  List<Id3Frame> id3Frames = new ArrayList<>();
  ParsableByteArray id3Data = new ParsableByteArray(data, size);

  Id3Header id3Header = decodeHeader(id3Data);
  if (id3Header == null) {
    return null;
  }

  int startPosition = id3Data.getPosition();
  int frameHeaderSize = id3Header.majorVersion == 2 ? 6 : 10;
  int framesSize = id3Header.framesSize;
  if (id3Header.isUnsynchronized) {
    framesSize = removeUnsynchronization(id3Data, id3Header.framesSize);
  }
  id3Data.setLimit(startPosition + framesSize);

  boolean unsignedIntFrameSizeHack = false;
  if (!validateFrames(id3Data, id3Header.majorVersion, frameHeaderSize, false)) {
    if (id3Header.majorVersion == 4 && validateFrames(id3Data, 4, frameHeaderSize, true)) {
      unsignedIntFrameSizeHack = true;
    } else {
      Log.w(TAG, "Failed to validate ID3 tag with majorVersion=" + id3Header.majorVersion);
      return null;
    }
  }

  while (id3Data.bytesLeft() >= frameHeaderSize) {
    Id3Frame frame = decodeFrame(id3Header.majorVersion, id3Data, unsignedIntFrameSizeHack,
        frameHeaderSize, framePredicate);
    if (frame != null) {
      id3Frames.add(frame);
    }
  }

  return new Metadata(id3Frames);
}
 
Example 30
private void parseAndDiscardSamples() {
  while (sampleQueue.hasNextSample()) {
    MetadataInputBuffer inputBuffer = dequeueSample();
    if (inputBuffer == null) {
      continue;
    }
    long eventTimeUs = inputBuffer.timeUs;
    Metadata metadata = decoder.decode(inputBuffer);
    EventMessage eventMessage = (EventMessage) metadata.get(0);
    if (isPlayerEmsgEvent(eventMessage.schemeIdUri, eventMessage.value)) {
      parsePlayerEmsgEvent(eventTimeUs, eventMessage);
    }
  }
  sampleQueue.discardToRead();
}