Search in sources :

Example 1 with GuardedBy

use of androidx.annotation.GuardedBy in project ExoPlayer by google.

the class ConcatenatingMediaSource method setPublicShuffleOrder.

@GuardedBy("this")
private void setPublicShuffleOrder(ShuffleOrder shuffleOrder, @Nullable Handler handler, @Nullable Runnable onCompletionAction) {
    Assertions.checkArgument((handler == null) == (onCompletionAction == null));
    @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
    if (playbackThreadHandler != null) {
        int size = getSize();
        if (shuffleOrder.getLength() != size) {
            shuffleOrder = shuffleOrder.cloneAndClear().cloneAndInsert(/* insertionIndex= */
            0, /* insertionCount= */
            size);
        }
        @Nullable HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
        playbackThreadHandler.obtainMessage(MSG_SET_SHUFFLE_ORDER, new MessageData<>(/* index= */
        0, shuffleOrder, callbackAction)).sendToTarget();
    } else {
        this.shuffleOrder = shuffleOrder.getLength() > 0 ? shuffleOrder.cloneAndClear() : shuffleOrder;
        if (onCompletionAction != null && handler != null) {
            handler.post(onCompletionAction);
        }
    }
}
Also used : Handler(android.os.Handler) Nullable(androidx.annotation.Nullable) GuardedBy(androidx.annotation.GuardedBy)

Example 2 with GuardedBy

use of androidx.annotation.GuardedBy in project ExoPlayer by google.

the class ConcatenatingMediaSource method addPublicMediaSources.

// Internal methods. Called from any thread.
@GuardedBy("this")
private void addPublicMediaSources(int index, Collection<MediaSource> mediaSources, @Nullable Handler handler, @Nullable Runnable onCompletionAction) {
    Assertions.checkArgument((handler == null) == (onCompletionAction == null));
    @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
    for (MediaSource mediaSource : mediaSources) {
        Assertions.checkNotNull(mediaSource);
    }
    List<MediaSourceHolder> mediaSourceHolders = new ArrayList<>(mediaSources.size());
    for (MediaSource mediaSource : mediaSources) {
        mediaSourceHolders.add(new MediaSourceHolder(mediaSource, useLazyPreparation));
    }
    mediaSourcesPublic.addAll(index, mediaSourceHolders);
    if (playbackThreadHandler != null && !mediaSources.isEmpty()) {
        @Nullable HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
        playbackThreadHandler.obtainMessage(MSG_ADD, new MessageData<>(index, mediaSourceHolders, callbackAction)).sendToTarget();
    } else if (onCompletionAction != null && handler != null) {
        handler.post(onCompletionAction);
    }
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder) ArrayList(java.util.ArrayList) Handler(android.os.Handler) Nullable(androidx.annotation.Nullable) GuardedBy(androidx.annotation.GuardedBy)

Example 3 with GuardedBy

use of androidx.annotation.GuardedBy in project ExoPlayer by google.

the class ConcatenatingMediaSource method movePublicMediaSource.

@GuardedBy("this")
private void movePublicMediaSource(int currentIndex, int newIndex, @Nullable Handler handler, @Nullable Runnable onCompletionAction) {
    Assertions.checkArgument((handler == null) == (onCompletionAction == null));
    @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
    mediaSourcesPublic.add(newIndex, mediaSourcesPublic.remove(currentIndex));
    if (playbackThreadHandler != null) {
        @Nullable HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
        playbackThreadHandler.obtainMessage(MSG_MOVE, new MessageData<>(currentIndex, newIndex, callbackAction)).sendToTarget();
    } else if (onCompletionAction != null && handler != null) {
        handler.post(onCompletionAction);
    }
}
Also used : Handler(android.os.Handler) Nullable(androidx.annotation.Nullable) GuardedBy(androidx.annotation.GuardedBy)

Example 4 with GuardedBy

use of androidx.annotation.GuardedBy in project ExoPlayer by google.

the class ConcatenatingMediaSource method removePublicMediaSources.

@GuardedBy("this")
private void removePublicMediaSources(int fromIndex, int toIndex, @Nullable Handler handler, @Nullable Runnable onCompletionAction) {
    Assertions.checkArgument((handler == null) == (onCompletionAction == null));
    @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
    Util.removeRange(mediaSourcesPublic, fromIndex, toIndex);
    if (playbackThreadHandler != null) {
        @Nullable HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
        playbackThreadHandler.obtainMessage(MSG_REMOVE, new MessageData<>(fromIndex, toIndex, callbackAction)).sendToTarget();
    } else if (onCompletionAction != null && handler != null) {
        handler.post(onCompletionAction);
    }
}
Also used : Handler(android.os.Handler) Nullable(androidx.annotation.Nullable) GuardedBy(androidx.annotation.GuardedBy)

Aggregations

Handler (android.os.Handler)4 GuardedBy (androidx.annotation.GuardedBy)4 Nullable (androidx.annotation.Nullable)4 MediaSourceHolder (com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)1 ArrayList (java.util.ArrayList)1