Search in sources :

Example 11 with Metadata

use of com.google.android.exoplayer2.metadata.Metadata in project ExoPlayer by google.

the class SimpleExoPlayerView method updateForCurrentTrackSelections.

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();
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray)

Example 12 with Metadata

use of com.google.android.exoplayer2.metadata.Metadata in project ExoPlayer by google.

the class SimpleExoPlayerView method setArtworkFromMetadata.

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;
}
Also used : Bitmap(android.graphics.Bitmap) ApicFrame(com.google.android.exoplayer2.metadata.id3.ApicFrame) Metadata(com.google.android.exoplayer2.metadata.Metadata)

Example 13 with Metadata

use of com.google.android.exoplayer2.metadata.Metadata in project ExoPlayer by google.

the class HlsSampleStreamWrapper method buildTracks.

/**
   * Builds tracks that are exposed by this {@link HlsSampleStreamWrapper} instance, as well as
   * internal data-structures required for operation.
   * <p>
   * Tracks in HLS are complicated. A HLS master playlist contains a number of "variants". Each
   * variant stream typically contains muxed video, audio and (possibly) additional audio, metadata
   * and caption tracks. We wish to allow the user to select between an adaptive track that spans
   * all variants, as well as each individual variant. If multiple audio tracks are present within
   * each variant then we wish to allow the user to select between those also.
   * <p>
   * To do this, tracks are constructed as follows. The {@link HlsChunkSource} exposes (N+1) tracks,
   * where N is the number of variants defined in the HLS master playlist. These consist of one
   * adaptive track defined to span all variants and a track for each individual variant. The
   * adaptive track is initially selected. The extractor is then prepared to discover the tracks
   * inside of each variant stream. The two sets of tracks are then combined by this method to
   * create a third set, which is the set exposed by this {@link HlsSampleStreamWrapper}:
   * <ul>
   * <li>The extractor tracks are inspected to infer a "primary" track type. If a video track is
   * present then it is always the primary type. If not, audio is the primary type if present.
   * Else text is the primary type if present. Else there is no primary type.</li>
   * <li>If there is exactly one extractor track of the primary type, it's expanded into (N+1)
   * exposed tracks, all of which correspond to the primary extractor track and each of which
   * corresponds to a different chunk source track. Selecting one of these tracks has the effect
   * of switching the selected track on the chunk source.</li>
   * <li>All other extractor tracks are exposed directly. Selecting one of these tracks has the
   * effect of selecting an extractor track, leaving the selected track on the chunk source
   * unchanged.</li>
   * </ul>
   */
private void buildTracks() {
    // Iterate through the extractor tracks to discover the "primary" track type, and the index
    // of the single track of this type.
    int primaryExtractorTrackType = PRIMARY_TYPE_NONE;
    int primaryExtractorTrackIndex = C.INDEX_UNSET;
    int extractorTrackCount = sampleQueues.size();
    for (int i = 0; i < extractorTrackCount; i++) {
        String sampleMimeType = sampleQueues.valueAt(i).getUpstreamFormat().sampleMimeType;
        int trackType;
        if (MimeTypes.isVideo(sampleMimeType)) {
            trackType = PRIMARY_TYPE_VIDEO;
        } else if (MimeTypes.isAudio(sampleMimeType)) {
            trackType = PRIMARY_TYPE_AUDIO;
        } else if (MimeTypes.isText(sampleMimeType)) {
            trackType = PRIMARY_TYPE_TEXT;
        } else {
            trackType = PRIMARY_TYPE_NONE;
        }
        if (trackType > primaryExtractorTrackType) {
            primaryExtractorTrackType = trackType;
            primaryExtractorTrackIndex = i;
        } else if (trackType == primaryExtractorTrackType && primaryExtractorTrackIndex != C.INDEX_UNSET) {
            // We have multiple tracks of the primary type. We only want an index if there only exists a
            // single track of the primary type, so unset the index again.
            primaryExtractorTrackIndex = C.INDEX_UNSET;
        }
    }
    TrackGroup chunkSourceTrackGroup = chunkSource.getTrackGroup();
    int chunkSourceTrackCount = chunkSourceTrackGroup.length;
    // Instantiate the necessary internal data-structures.
    primaryTrackGroupIndex = C.INDEX_UNSET;
    groupEnabledStates = new boolean[extractorTrackCount];
    // Construct the set of exposed track groups.
    TrackGroup[] trackGroups = new TrackGroup[extractorTrackCount];
    for (int i = 0; i < extractorTrackCount; i++) {
        Format sampleFormat = sampleQueues.valueAt(i).getUpstreamFormat();
        if (i == primaryExtractorTrackIndex) {
            Format[] formats = new Format[chunkSourceTrackCount];
            for (int j = 0; j < chunkSourceTrackCount; j++) {
                formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat);
            }
            trackGroups[i] = new TrackGroup(formats);
            primaryTrackGroupIndex = i;
        } else {
            Format trackFormat = primaryExtractorTrackType == PRIMARY_TYPE_VIDEO && MimeTypes.isAudio(sampleFormat.sampleMimeType) ? muxedAudioFormat : null;
            trackGroups[i] = new TrackGroup(deriveFormat(trackFormat, sampleFormat));
        }
    }
    this.trackGroups = new TrackGroupArray(trackGroups);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray)

Example 14 with Metadata

use of com.google.android.exoplayer2.metadata.Metadata in project dhis2-core by dhis2.

the class DefaultSynchronizationManager method executeMetadataPull.

@Override
public ImportReport executeMetadataPull(String url) {
    User user = currentUserService.getCurrentUser();
    String userUid = user != null ? user.getUid() : null;
    log.info(String.format("Metadata pull, url: %s, user: %s", url, userUid));
    String json = restTemplate.getForObject(url, String.class);
    Metadata metadata = null;
    try {
        metadata = DefaultRenderService.getJsonMapper().readValue(json, Metadata.class);
    } catch (IOException ex) {
        throw new RuntimeException("Failed to parse remote JSON document", ex);
    }
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setSkipSharing(true);
    importParams.setAtomicMode(AtomicMode.NONE);
    importParams.addMetadata(schemaService.getMetadataSchemas(), metadata);
    return importService.importMetadata(importParams);
}
Also used : User(org.hisp.dhis.user.User) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) IOException(java.io.IOException)

Example 15 with Metadata

use of com.google.android.exoplayer2.metadata.Metadata in project dhis2-core by dhis2.

the class ImportMetaDataTask method call.

@Override
public void call() {
    Metadata metadata;
    try {
        if ("json".equals(format)) {
            metadata = DefaultRenderService.getJsonMapper().readValue(inputStream, Metadata.class);
            log.info("Read JSON file. Importing metadata.");
        } else {
            metadata = DefaultRenderService.getXmlMapper().readValue(inputStream, Metadata.class);
            log.info("Read XML file. Importing metadata.");
        }
    } catch (IOException ex) {
        log.error(DebugUtils.getStackTrace(ex));
        throw new RuntimeException("Failed to parse meta data input stream", ex);
    }
    importParams.addMetadata(schemaService.getMetadataSchemas(), metadata);
    importService.importMetadata(importParams);
}
Also used : Metadata(org.hisp.dhis.dxf2.metadata.Metadata) IOException(java.io.IOException)

Aggregations

Metadata (com.google.android.exoplayer2.metadata.Metadata)18 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)6 IOException (java.io.IOException)5 Format (com.google.android.exoplayer2.Format)3 ArrayList (java.util.ArrayList)3 MediaFormat (android.media.MediaFormat)2 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)2 ApicFrame (com.google.android.exoplayer2.metadata.id3.ApicFrame)2 Id3Frame (com.google.android.exoplayer2.metadata.id3.Id3Frame)2 PrivFrame (com.google.android.exoplayer2.metadata.id3.PrivFrame)2 TextInformationFrame (com.google.android.exoplayer2.metadata.id3.TextInformationFrame)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)2 FlacStreamInfo (com.google.android.exoplayer2.util.FlacStreamInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2