Search in sources :

Example 1 with IcyHeaders

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

the class ProgressiveMediaPeriod method maybeFinishPrepare.

private void maybeFinishPrepare() {
    if (released || prepared || !sampleQueuesBuilt || seekMap == null) {
        return;
    }
    for (SampleQueue sampleQueue : sampleQueues) {
        if (sampleQueue.getUpstreamFormat() == null) {
            return;
        }
    }
    loadCondition.close();
    int trackCount = sampleQueues.length;
    TrackGroup[] trackArray = new TrackGroup[trackCount];
    boolean[] trackIsAudioVideoFlags = new boolean[trackCount];
    for (int i = 0; i < trackCount; i++) {
        Format trackFormat = Assertions.checkNotNull(sampleQueues[i].getUpstreamFormat());
        @Nullable String mimeType = trackFormat.sampleMimeType;
        boolean isAudio = MimeTypes.isAudio(mimeType);
        boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
        trackIsAudioVideoFlags[i] = isAudioVideo;
        haveAudioVideoTracks |= isAudioVideo;
        @Nullable IcyHeaders icyHeaders = this.icyHeaders;
        if (icyHeaders != null) {
            if (isAudio || sampleQueueTrackIds[i].isIcyTrack) {
                @Nullable Metadata metadata = trackFormat.metadata;
                if (metadata == null) {
                    metadata = new Metadata(icyHeaders);
                } else {
                    metadata = metadata.copyWithAppendedEntries(icyHeaders);
                }
                trackFormat = trackFormat.buildUpon().setMetadata(metadata).build();
            }
            // an average or peak bitrate of its own.
            if (isAudio && trackFormat.averageBitrate == Format.NO_VALUE && trackFormat.peakBitrate == Format.NO_VALUE && icyHeaders.bitrate != Format.NO_VALUE) {
                trackFormat = trackFormat.buildUpon().setAverageBitrate(icyHeaders.bitrate).build();
            }
        }
        trackFormat = trackFormat.copyWithCryptoType(drmSessionManager.getCryptoType(trackFormat));
        trackArray[i] = new TrackGroup(/* id= */
        Integer.toString(i), trackFormat);
    }
    trackState = new TrackState(new TrackGroupArray(trackArray), trackIsAudioVideoFlags);
    prepared = true;
    Assertions.checkNotNull(callback).onPrepared(this);
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata) IcyHeaders(com.google.android.exoplayer2.metadata.icy.IcyHeaders) Format(com.google.android.exoplayer2.Format) Nullable(androidx.annotation.Nullable)

Example 2 with IcyHeaders

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

the class IcyHeadersTest method populateMediaMetadata.

@Test
public void populateMediaMetadata() {
    IcyHeaders headers = new IcyHeaders(/* bitrate= */
    1234, /* genre= */
    "pop", /* name= */
    "radio station", /* url= */
    "url", /* isPublic= */
    true, /* metadataInterval= */
    5678);
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    headers.populateMediaMetadata(builder);
    MediaMetadata mediaMetadata = builder.build();
    assertThat(mediaMetadata.station.toString()).isEqualTo("radio station");
    assertThat(mediaMetadata.genre.toString()).isEqualTo("pop");
}
Also used : MediaMetadata(com.google.android.exoplayer2.MediaMetadata) Test(org.junit.Test)

Aggregations

Nullable (androidx.annotation.Nullable)1 Format (com.google.android.exoplayer2.Format)1 MediaMetadata (com.google.android.exoplayer2.MediaMetadata)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 IcyHeaders (com.google.android.exoplayer2.metadata.icy.IcyHeaders)1 Test (org.junit.Test)1