Search in sources :

Example 6 with MediaMetadata

use of com.google.android.exoplayer2.MediaMetadata 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 7 with MediaMetadata

use of com.google.android.exoplayer2.MediaMetadata 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 8 with MediaMetadata

use of com.google.android.exoplayer2.MediaMetadata 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 9 with MediaMetadata

use of com.google.android.exoplayer2.MediaMetadata in project ExoPlayer by google.

the class ExoPlayerTest method playingMedia_withNoMetadata_doesNotUpdateMediaMetadata.

@Test
public void playingMedia_withNoMetadata_doesNotUpdateMediaMetadata() throws Exception {
    MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("the title").build();
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    MediaItem mediaItem = new MediaItem.Builder().setMediaId("id").setUri(Uri.parse("asset://android_asset/media/mp4/sample.mp4")).setMediaMetadata(mediaMetadata).build();
    player.setMediaItem(mediaItem);
    assertThat(player.getMediaMetadata()).isEqualTo(mediaMetadata);
    player.prepare();
    TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
    0, /* positionMs= */
    5 * C.MILLIS_PER_SECOND);
    player.stop();
    shadowOf(Looper.getMainLooper()).idle();
    assertThat(player.getMediaMetadata()).isEqualTo(mediaMetadata);
}
Also used : TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 10 with MediaMetadata

use of com.google.android.exoplayer2.MediaMetadata in project Signal-Android by WhisperSystems.

the class VoiceNotePlaybackPreparer method indexAfter.

private int indexAfter(@NonNull MediaItem target) {
    int size = player.getMediaItemCount();
    long targetMessageId = target.mediaMetadata.extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
    for (int i = 0; i < size; i++) {
        MediaMetadata mediaMetadata = player.getMediaItemAt(i).mediaMetadata;
        long messageId = mediaMetadata.extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
        if (messageId > targetMessageId) {
            return i;
        }
    }
    return size;
}
Also used : MediaMetadata(com.google.android.exoplayer2.MediaMetadata)

Aggregations

Test (org.junit.Test)10 MediaMetadata (com.google.android.exoplayer2.MediaMetadata)8 Metadata (com.google.android.exoplayer2.metadata.Metadata)4 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)3 SuppressLint (android.annotation.SuppressLint)2 Context (android.content.Context)2 Nullable (androidx.annotation.Nullable)2 MediaItem (com.google.android.exoplayer2.MediaItem)2 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)2 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)2 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)2 ArrayList (java.util.ArrayList)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)1 TextUtils (android.text.TextUtils)1 ContextCompat (androidx.core.content.ContextCompat)1 CallbackMediaItem (androidx.media2.common.CallbackMediaItem)1