Search in sources :

Example 11 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class TextInformationFrameTest method populateMediaMetadata_setsBuilderValues.

@Test
public void populateMediaMetadata_setsBuilderValues() {
    String title = "the title";
    String artist = "artist";
    String albumTitle = "album title";
    String albumArtist = "album Artist";
    String trackNumberInfo = "11/17";
    String recordingYear = "2000";
    String recordingMonth = "07";
    String recordingDay = "10";
    String releaseDate = "2001-01-02T00:00:00";
    String composer = "composer";
    String conductor = "conductor";
    String writer = "writer";
    List<Metadata.Entry> entries = ImmutableList.of(new TextInformationFrame(/* id= */
    "TT2", /* description= */
    null, /* value= */
    title), new TextInformationFrame(/* id= */
    "TP1", /* description= */
    null, /* value= */
    artist), new TextInformationFrame(/* id= */
    "TAL", /* description= */
    null, /* value= */
    albumTitle), new TextInformationFrame(/* id= */
    "TP2", /* description= */
    null, /* value= */
    albumArtist), new TextInformationFrame(/* id= */
    "TRK", /* description= */
    null, /* value= */
    trackNumberInfo), new TextInformationFrame(/* id= */
    "TYE", /* description= */
    null, /* value= */
    recordingYear), new TextInformationFrame(/* id= */
    "TDA", /* description= */
    null, /* value= */
    recordingDay + recordingMonth), new TextInformationFrame(/* id= */
    "TDRL", /* description= */
    null, /* value= */
    releaseDate), new TextInformationFrame(/* id= */
    "TCM", /* description= */
    null, /* value= */
    composer), new TextInformationFrame(/* id= */
    "TP3", /* description= */
    null, /* value= */
    conductor), new TextInformationFrame(/* id= */
    "TXT", /* description= */
    null, /* value= */
    writer));
    MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
    for (Metadata.Entry entry : entries) {
        entry.populateMediaMetadata(builder);
    }
    MediaMetadata mediaMetadata = builder.build();
    assertThat(mediaMetadata.title.toString()).isEqualTo(title);
    assertThat(mediaMetadata.artist.toString()).isEqualTo(artist);
    assertThat(mediaMetadata.albumTitle.toString()).isEqualTo(albumTitle);
    assertThat(mediaMetadata.albumArtist.toString()).isEqualTo(albumArtist);
    assertThat(mediaMetadata.trackNumber).isEqualTo(11);
    assertThat(mediaMetadata.totalTrackCount).isEqualTo(17);
    assertThat(mediaMetadata.recordingYear).isEqualTo(2000);
    assertThat(mediaMetadata.recordingMonth).isEqualTo(7);
    assertThat(mediaMetadata.recordingDay).isEqualTo(10);
    assertThat(mediaMetadata.releaseYear).isEqualTo(2001);
    assertThat(mediaMetadata.releaseMonth).isEqualTo(1);
    assertThat(mediaMetadata.releaseDay).isEqualTo(2);
    assertThat(mediaMetadata.composer.toString()).isEqualTo(composer);
    assertThat(mediaMetadata.conductor.toString()).isEqualTo(conductor);
    assertThat(mediaMetadata.writer.toString()).isEqualTo(writer);
}
Also used : MediaMetadata(com.google.android.exoplayer2.MediaMetadata) Metadata(com.google.android.exoplayer2.metadata.Metadata) MediaMetadata(com.google.android.exoplayer2.MediaMetadata) Test(org.junit.Test)

Example 12 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class VorbisCommentTest method populateMediaMetadata_setsMediaMetadataValues.

@Test
public void populateMediaMetadata_setsMediaMetadataValues() {
    String title = "the title";
    String artist = "artist";
    String albumTitle = "album title";
    String albumArtist = "album Artist";
    String description = "a description about the audio.";
    List<Metadata.Entry> entries = ImmutableList.of(new VorbisComment("TITLE", title), new VorbisComment("ARTIST", artist), new VorbisComment("ALBUM", albumTitle), new VorbisComment("ALBUMARTIST", albumArtist), new VorbisComment("DESCRIPTION", description));
    MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
    for (Metadata.Entry entry : entries) {
        entry.populateMediaMetadata(builder);
    }
    MediaMetadata mediaMetadata = builder.build();
    assertThat(mediaMetadata.title.toString()).isEqualTo(title);
    assertThat(mediaMetadata.artist.toString()).isEqualTo(artist);
    assertThat(mediaMetadata.albumTitle.toString()).isEqualTo(albumTitle);
    assertThat(mediaMetadata.albumArtist.toString()).isEqualTo(albumArtist);
    assertThat(mediaMetadata.description.toString()).isEqualTo(description);
}
Also used : MediaMetadata(com.google.android.exoplayer2.MediaMetadata) Metadata(com.google.android.exoplayer2.metadata.Metadata) MediaMetadata(com.google.android.exoplayer2.MediaMetadata) Test(org.junit.Test)

Example 13 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class ApicFrameTest method populateMediaMetadata_setsBuilderValues.

@Test
public void populateMediaMetadata_setsBuilderValues() {
    byte[] pictureData = new byte[] { -12, 52, 33, 85, 34, 22, 1, -55 };
    @MediaMetadata.PictureType int pictureType = MediaMetadata.PICTURE_TYPE_LEAFLET_PAGE;
    Metadata.Entry entry = new ApicFrame(/* mimeType= */
    MimeTypes.BASE_TYPE_IMAGE, /* description= */
    "an image", pictureType, pictureData);
    MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
    entry.populateMediaMetadata(builder);
    MediaMetadata mediaMetadata = builder.build();
    assertThat(mediaMetadata.artworkData).isEqualTo(pictureData);
    assertThat(mediaMetadata.artworkDataType).isEqualTo(pictureType);
}
Also used : MediaMetadata(com.google.android.exoplayer2.MediaMetadata) Metadata(com.google.android.exoplayer2.metadata.Metadata) MediaMetadata(com.google.android.exoplayer2.MediaMetadata) Test(org.junit.Test)

Example 14 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class TtmlRenderUtil method applyStylesToSpan.

public static void applyStylesToSpan(Spannable builder, int start, int end, TtmlStyle style, @Nullable TtmlNode parent, Map<String, TtmlStyle> globalStyles, @Cue.VerticalType int verticalType) {
    if (style.getStyle() != TtmlStyle.UNSPECIFIED) {
        builder.setSpan(new StyleSpan(style.getStyle()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (style.isLinethrough()) {
        builder.setSpan(new StrikethroughSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (style.isUnderline()) {
        builder.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (style.hasFontColor()) {
        SpanUtil.addOrReplaceSpan(builder, new ForegroundColorSpan(style.getFontColor()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (style.hasBackgroundColor()) {
        SpanUtil.addOrReplaceSpan(builder, new BackgroundColorSpan(style.getBackgroundColor()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (style.getFontFamily() != null) {
        SpanUtil.addOrReplaceSpan(builder, new TypefaceSpan(style.getFontFamily()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (style.getTextEmphasis() != null) {
        TextEmphasis textEmphasis = checkNotNull(style.getTextEmphasis());
        @TextEmphasisSpan.MarkShape int markShape;
        @TextEmphasisSpan.MarkFill int markFill;
        if (textEmphasis.markShape == TextEmphasis.MARK_SHAPE_AUTO) {
            // If a vertical writing mode applies, then 'auto' is equivalent to 'filled sesame';
            // otherwise, it's equivalent to 'filled circle':
            // https://www.w3.org/TR/ttml2/#style-value-emphasis-style
            markShape = (verticalType == Cue.VERTICAL_TYPE_LR || verticalType == Cue.VERTICAL_TYPE_RL) ? TextEmphasisSpan.MARK_SHAPE_SESAME : TextEmphasisSpan.MARK_SHAPE_CIRCLE;
            markFill = TextEmphasisSpan.MARK_FILL_FILLED;
        } else {
            markShape = textEmphasis.markShape;
            markFill = textEmphasis.markFill;
        }
        @TextEmphasis.Position int position;
        if (textEmphasis.position == TextEmphasis.POSITION_OUTSIDE) {
            // 'outside' is not supported by TextEmphasisSpan, so treat it as 'before':
            // https://www.w3.org/TR/ttml2/#style-value-annotation-position
            position = TextAnnotation.POSITION_BEFORE;
        } else {
            position = textEmphasis.position;
        }
        SpanUtil.addOrReplaceSpan(builder, new TextEmphasisSpan(markShape, markFill, position), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    switch(style.getRubyType()) {
        case TtmlStyle.RUBY_TYPE_BASE:
            // look for the sibling RUBY_TEXT and add it as span between start & end.
            @Nullable TtmlNode containerNode = findRubyContainerNode(parent, globalStyles);
            if (containerNode == null) {
                // No matching container node
                break;
            }
            @Nullable TtmlNode textNode = findRubyTextNode(containerNode, globalStyles);
            if (textNode == null) {
                // no matching text node
                break;
            }
            String rubyText;
            if (textNode.getChildCount() == 1 && textNode.getChild(0).text != null) {
                rubyText = Util.castNonNull(textNode.getChild(0).text);
            } else {
                Log.i(TAG, "Skipping rubyText node without exactly one text child.");
                break;
            }
            @Nullable TtmlStyle textStyle = resolveStyle(textNode.style, textNode.getStyleIds(), globalStyles);
            // Use position from ruby text node if defined.
            @TextAnnotation.Position int rubyPosition = textStyle != null ? textStyle.getRubyPosition() : TextAnnotation.POSITION_UNKNOWN;
            if (rubyPosition == TextAnnotation.POSITION_UNKNOWN) {
                // If ruby position is not defined, use position info from container node.
                @Nullable TtmlStyle containerStyle = resolveStyle(containerNode.style, containerNode.getStyleIds(), globalStyles);
                rubyPosition = containerStyle != null ? containerStyle.getRubyPosition() : rubyPosition;
            }
            builder.setSpan(new RubySpan(rubyText, rubyPosition), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TtmlStyle.RUBY_TYPE_DELIMITER:
        // fall through and delete the text.
        case TtmlStyle.RUBY_TYPE_TEXT:
            // We can't just remove the text directly from `builder` here because TtmlNode has fixed
            // ideas of where every node starts and ends (nodeStartsByRegion and nodeEndsByRegion) so
            // all these indices become invalid if we mutate the underlying string at this point.
            // Instead we add a special span that's then handled in TtmlNode#cleanUpText.
            builder.setSpan(new DeleteTextSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TtmlStyle.RUBY_TYPE_CONTAINER:
        case TtmlStyle.UNSPECIFIED:
        default:
            // Do nothing
            break;
    }
    if (style.getTextCombine()) {
        SpanUtil.addOrReplaceSpan(builder, new HorizontalTextInVerticalContextSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    switch(style.getFontSizeUnit()) {
        case TtmlStyle.FONT_SIZE_UNIT_PIXEL:
            SpanUtil.addOrReplaceSpan(builder, new AbsoluteSizeSpan((int) style.getFontSize(), true), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TtmlStyle.FONT_SIZE_UNIT_EM:
            SpanUtil.addOrReplaceSpan(builder, new RelativeSizeSpan(style.getFontSize()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TtmlStyle.FONT_SIZE_UNIT_PERCENT:
            SpanUtil.addOrReplaceSpan(builder, new RelativeSizeSpan(style.getFontSize() / 100), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            break;
        case TtmlStyle.UNSPECIFIED:
            // Do nothing.
            break;
    }
}
Also used : RubySpan(com.google.android.exoplayer2.text.span.RubySpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextEmphasisSpan(com.google.android.exoplayer2.text.span.TextEmphasisSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) HorizontalTextInVerticalContextSpan(com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan) StyleSpan(android.text.style.StyleSpan) BackgroundColorSpan(android.text.style.BackgroundColorSpan) Nullable(androidx.annotation.Nullable) StrikethroughSpan(android.text.style.StrikethroughSpan) TypefaceSpan(android.text.style.TypefaceSpan)

Example 15 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project zype-android by zype.

the class PlayerFragment method updatePositionLive.

private void updatePositionLive(Timeline timeline, long position) {
    Timeline.Window window = new Timeline.Window();
    timeline.getWindow(0, window);
    long duration = C.usToMs(window.durationUs);
    StringBuilder builder = new StringBuilder();
    Formatter formatter = new Formatter(builder, Locale.getDefault());
    textPositionLive.setText("-" + Util.getStringForTime(builder, formatter, duration - position));
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) Formatter(java.util.Formatter)

Aggregations

Test (org.junit.Test)12 Nullable (androidx.annotation.Nullable)7 MediaItem (com.google.android.exoplayer2.MediaItem)6 MediaMetadata (com.google.android.exoplayer2.MediaMetadata)5 Metadata (com.google.android.exoplayer2.metadata.Metadata)4 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)3 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)3 ImmutableList (com.google.common.collect.ImmutableList)3 Bundle (android.os.Bundle)2 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 MediaQueueItem (com.google.android.gms.cast.MediaQueueItem)2 SurfaceTexture (android.graphics.SurfaceTexture)1 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)1 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)1 BackgroundColorSpan (android.text.style.BackgroundColorSpan)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 RelativeSizeSpan (android.text.style.RelativeSizeSpan)1 StrikethroughSpan (android.text.style.StrikethroughSpan)1