Search in sources :

Example 11 with MediaMetadata

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

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)

Example 12 with MediaMetadata

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

the class SessionCallbackBuilderTest method setMediaItemProvider_withMediaItemProvider_receivesOnCreateMediaItem.

@Test
public void setMediaItemProvider_withMediaItemProvider_receivesOnCreateMediaItem() throws Exception {
    Uri testMediaUri = RawResourceDataSource.buildRawResourceUri(R.raw.audio);
    CountDownLatch providerLatch = new CountDownLatch(1);
    SessionCallbackBuilder.MediaIdMediaItemProvider mediaIdMediaItemProvider = new SessionCallbackBuilder.MediaIdMediaItemProvider();
    SessionCallbackBuilder.MediaItemProvider provider = (session, controllerInfo, mediaId) -> {
        assertThat(mediaId).isEqualTo(testMediaUri.toString());
        providerLatch.countDown();
        return mediaIdMediaItemProvider.onCreateMediaItem(session, controllerInfo, mediaId);
    };
    CountDownLatch currentMediaItemChangedLatch = new CountDownLatch(1);
    sessionPlayerConnector.registerPlayerCallback(executor, new SessionPlayer.PlayerCallback() {

        @Override
        public void onCurrentMediaItemChanged(SessionPlayer player, MediaItem item) {
            MediaMetadata metadata = item.getMetadata();
            assertThat(metadata.getString(MediaMetadata.METADATA_KEY_MEDIA_ID)).isEqualTo(testMediaUri.toString());
            currentMediaItemChangedLatch.countDown();
        }
    });
    try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).setMediaItemProvider(provider).build())) {
        try (MediaController controller = createConnectedController(session)) {
            assertSessionResultSuccess(controller.setMediaItem(testMediaUri.toString()), PLAYER_STATE_CHANGE_OVER_SESSION_WAIT_TIME_MS);
            assertThat(providerLatch.await(0, MILLISECONDS)).isTrue();
            assertThat(currentMediaItemChangedLatch.await(CONTROLLER_COMMAND_WAIT_TIME_MS, MILLISECONDS)).isTrue();
        }
    }
}
Also used : Context(android.content.Context) HeartRating(androidx.media2.session.HeartRating) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Uri(android.net.Uri) MediaSession(androidx.media2.session.MediaSession) RunWith(org.junit.runner.RunWith) SessionResult(androidx.media2.session.SessionResult) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) TestUtils.assertPlayerResultSuccess(com.google.android.exoplayer2.ext.media2.TestUtils.assertPlayerResultSuccess) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SessionCommand(androidx.media2.session.SessionCommand) ContextCompat(androidx.core.content.ContextCompat) LargeTest(androidx.test.filters.LargeTest) Before(org.junit.Before) SessionPlayer(androidx.media2.common.SessionPlayer) MediaMetadata(androidx.media2.common.MediaMetadata) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Executor(java.util.concurrent.Executor) TextUtils(android.text.TextUtils) UriMediaItem(androidx.media2.common.UriMediaItem) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Truth.assertThat(com.google.common.truth.Truth.assertThat) MediaItem(androidx.media2.common.MediaItem) Rating(androidx.media2.common.Rating) R(com.google.android.exoplayer2.ext.media2.test.R) CountDownLatch(java.util.concurrent.CountDownLatch) SessionCommandGroup(androidx.media2.session.SessionCommandGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) MediaController(androidx.media2.session.MediaController) RawResourceDataSource(com.google.android.exoplayer2.upstream.RawResourceDataSource) MediaController(androidx.media2.session.MediaController) SessionPlayer(androidx.media2.common.SessionPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) Uri(android.net.Uri) MediaSession(androidx.media2.session.MediaSession) UriMediaItem(androidx.media2.common.UriMediaItem) MediaItem(androidx.media2.common.MediaItem) MediaMetadata(androidx.media2.common.MediaMetadata) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 13 with MediaMetadata

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

the class DefaultAnalyticsCollector method onPlaylistMetadataChanged.

@Override
public void onPlaylistMetadataChanged(MediaMetadata playlistMetadata) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_PLAYLIST_METADATA_CHANGED, listener -> listener.onPlaylistMetadataChanged(eventTime, playlistMetadata));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 14 with MediaMetadata

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

the class ExoPlayerTest method onPlaylistMetadataChanged_calledWhenPlaylistMetadataSet.

@Test
public void onPlaylistMetadataChanged_calledWhenPlaylistMetadataSet() {
    ExoPlayer player = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).build();
    Player.Listener playerListener = mock(Player.Listener.class);
    player.addListener(playerListener);
    AnalyticsListener analyticsListener = mock(AnalyticsListener.class);
    player.addAnalyticsListener(analyticsListener);
    MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("test").build();
    player.setPlaylistMetadata(mediaMetadata);
    verify(playerListener).onPlaylistMetadataChanged(mediaMetadata);
    verify(analyticsListener).onPlaylistMetadataChanged(any(), eq(mediaMetadata));
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Example 15 with MediaMetadata

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

the class PictureFrameTest method populateMediaMetadata_setsBuilderValues.

@Test
public void populateMediaMetadata_setsBuilderValues() {
    byte[] pictureData = new byte[] { -12, 52, 33, 85, 34, 22, 1, -55 };
    Metadata.Entry entry = new PictureFrame(/* pictureType= */
    MediaMetadata.PICTURE_TYPE_FRONT_COVER, /* mimeType= */
    MimeTypes.IMAGE_JPEG, /* description= */
    "an image", /* width= */
    4, /* height= */
    2, /* depth= */
    1, /* colors= */
    1, pictureData);
    MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
    entry.populateMediaMetadata(builder);
    MediaMetadata mediaMetadata = builder.build();
    assertThat(mediaMetadata.artworkData).isEqualTo(pictureData);
    assertThat(mediaMetadata.artworkDataType).isEqualTo(MediaMetadata.PICTURE_TYPE_FRONT_COVER);
}
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)

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