Search in sources :

Example 96 with MediaItem

use of com.google.android.exoplayer2.MediaItem 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)

Example 97 with MediaItem

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

the class VoiceNotePlaybackPreparer method loadMediaItemsForSinglePlayback.

@NonNull
private List<MediaItem> loadMediaItemsForSinglePlayback(long messageId) {
    try {
        MessageRecord messageRecord = SignalDatabase.mms().getMessageRecord(messageId);
        if (!MessageRecordUtil.hasAudio(messageRecord)) {
            Log.w(TAG, "Message does not contain audio.");
            return Collections.emptyList();
        }
        MediaItem mediaItem = VoiceNoteMediaItemFactory.buildMediaItem(context, messageRecord);
        if (mediaItem == null) {
            return Collections.emptyList();
        } else {
            return Collections.singletonList(mediaItem);
        }
    } catch (NoSuchMessageException e) {
        Log.w(TAG, "Could not find message.", e);
        return Collections.emptyList();
    }
}
Also used : NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) MediaItem(com.google.android.exoplayer2.MediaItem) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) NonNull(androidx.annotation.NonNull)

Example 98 with MediaItem

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

the class VoiceNotePlaybackPreparer method loadMoreVoiceNotes.

public void loadMoreVoiceNotes() {
    if (!canLoadMore) {
        return;
    }
    MediaItem currentMediaItem = player.getCurrentMediaItem();
    if (currentMediaItem == null) {
        return;
    }
    long messageId = currentMediaItem.mediaMetadata.extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
    SimpleTask.run(EXECUTOR, () -> loadMediaItemsForConsecutivePlayback(messageId), mediaItems -> {
        if (Util.hasItems(mediaItems) && canLoadMore) {
            applyDescriptionsToQueue(mediaItems);
        }
    });
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem)

Example 99 with MediaItem

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

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

the class VoiceNotePlaybackService method sendViewedReceiptForCurrentWindowIndex.

private void sendViewedReceiptForCurrentWindowIndex() {
    if (player.getPlaybackState() == Player.STATE_READY && player.getPlayWhenReady() && player.getCurrentWindowIndex() != C.INDEX_UNSET) {
        MediaItem currentMediaItem = player.getCurrentMediaItem();
        if (currentMediaItem == null || currentMediaItem.playbackProperties == null) {
            return;
        }
        Uri mediaUri = currentMediaItem.playbackProperties.uri;
        if (!mediaUri.getScheme().equals("content")) {
            return;
        }
        SignalExecutors.BOUNDED.execute(() -> {
            Bundle extras = currentMediaItem.mediaMetadata.extras;
            if (extras == null) {
                return;
            }
            long messageId = extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
            RecipientId recipientId = RecipientId.from(extras.getString(VoiceNoteMediaItemFactory.EXTRA_INDIVIDUAL_RECIPIENT_ID));
            MessageDatabase messageDatabase = SignalDatabase.mms();
            MessageDatabase.MarkedMessageInfo markedMessageInfo = messageDatabase.setIncomingMessageViewed(messageId);
            if (markedMessageInfo != null) {
                ApplicationDependencies.getJobManager().add(new SendViewedReceiptJob(markedMessageInfo.getThreadId(), recipientId, markedMessageInfo.getSyncMessageId().getTimetamp(), new MessageId(messageId, true)));
                MultiDeviceViewedUpdateJob.enqueue(Collections.singletonList(markedMessageInfo.getSyncMessageId()));
            }
        });
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MediaItem(com.google.android.exoplayer2.MediaItem) Bundle(android.os.Bundle) SendViewedReceiptJob(org.thoughtcrime.securesms.jobs.SendViewedReceiptJob) Uri(android.net.Uri) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)160 Test (org.junit.Test)151 MediaSource (com.google.android.exoplayer2.source.MediaSource)31 ArrayList (java.util.ArrayList)29 Timeline (com.google.android.exoplayer2.Timeline)25 InOrder (org.mockito.InOrder)20 Nullable (androidx.annotation.Nullable)19 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)19 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)19 Player (com.google.android.exoplayer2.Player)17 Uri (android.net.Uri)15 Listener (com.google.android.exoplayer2.Player.Listener)15 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)15 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)15 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)13 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)13 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)12