Search in sources :

Example 1 with FileMediaItem

use of androidx.media2.common.FileMediaItem in project ExoPlayer by google.

the class DefaultMediaItemConverter method convertToExoPlayerMediaItem.

@Override
public MediaItem convertToExoPlayerMediaItem(androidx.media2.common.MediaItem media2MediaItem) {
    if (media2MediaItem instanceof FileMediaItem) {
        throw new IllegalStateException("FileMediaItem isn't supported");
    }
    if (media2MediaItem instanceof CallbackMediaItem) {
        throw new IllegalStateException("CallbackMediaItem isn't supported");
    }
    @Nullable Uri uri = null;
    @Nullable String mediaId = null;
    @Nullable String title = null;
    if (media2MediaItem instanceof UriMediaItem) {
        UriMediaItem uriMediaItem = (UriMediaItem) media2MediaItem;
        uri = uriMediaItem.getUri();
    }
    @Nullable androidx.media2.common.MediaMetadata metadata = media2MediaItem.getMetadata();
    if (metadata != null) {
        @Nullable String uriString = metadata.getString(METADATA_KEY_MEDIA_URI);
        mediaId = metadata.getString(METADATA_KEY_MEDIA_ID);
        if (uri == null) {
            if (uriString != null) {
                uri = Uri.parse(uriString);
            } else if (mediaId != null) {
                uri = Uri.parse("media2:///" + mediaId);
            }
        }
        title = metadata.getString(METADATA_KEY_DISPLAY_TITLE);
        if (title == null) {
            title = metadata.getString(METADATA_KEY_TITLE);
        }
    }
    if (uri == null) {
        // Generate a URI to make it non-null. If not, then the tag passed to setTag will be ignored.
        uri = Uri.parse("media2:///");
    }
    long startPositionMs = media2MediaItem.getStartPosition();
    if (startPositionMs == androidx.media2.common.MediaItem.POSITION_UNKNOWN) {
        startPositionMs = 0;
    }
    long endPositionMs = media2MediaItem.getEndPosition();
    if (endPositionMs == androidx.media2.common.MediaItem.POSITION_UNKNOWN) {
        endPositionMs = C.TIME_END_OF_SOURCE;
    }
    return new MediaItem.Builder().setUri(uri).setMediaId(mediaId != null ? mediaId : MediaItem.DEFAULT_MEDIA_ID).setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build()).setTag(media2MediaItem).setClippingConfiguration(new MediaItem.ClippingConfiguration.Builder().setStartPositionMs(startPositionMs).setEndPositionMs(endPositionMs).build()).build();
}
Also used : CallbackMediaItem(androidx.media2.common.CallbackMediaItem) Uri(android.net.Uri) FileMediaItem(androidx.media2.common.FileMediaItem) Nullable(androidx.annotation.Nullable) UriMediaItem(androidx.media2.common.UriMediaItem)

Example 2 with FileMediaItem

use of androidx.media2.common.FileMediaItem in project ExoPlayer by google.

the class SessionPlayerConnector method setPlaylist.

/**
 * {@inheritDoc}
 *
 * <p>{@link FileMediaItem} and {@link CallbackMediaItem} are not supported.
 */
@Override
public ListenableFuture<PlayerResult> setPlaylist(final List<MediaItem> playlist, @Nullable MediaMetadata metadata) {
    Assertions.checkNotNull(playlist);
    Assertions.checkArgument(!playlist.isEmpty());
    for (int i = 0; i < playlist.size(); i++) {
        MediaItem item = playlist.get(i);
        Assertions.checkNotNull(item);
        Assertions.checkArgument(!(item instanceof FileMediaItem));
        Assertions.checkArgument(!(item instanceof CallbackMediaItem));
        for (int j = 0; j < i; j++) {
            Assertions.checkArgument(item != playlist.get(j), "playlist shouldn't contain duplicated item, index=" + i + " vs index=" + j);
        }
    }
    ListenableFuture<PlayerResult> result = playerCommandQueue.addCommand(PlayerCommandQueue.COMMAND_CODE_PLAYER_SET_PLAYLIST, /* command= */
    () -> player.setPlaylist(playlist, metadata));
    return result;
}
Also used : CallbackMediaItem(androidx.media2.common.CallbackMediaItem) MediaItem(androidx.media2.common.MediaItem) FileMediaItem(androidx.media2.common.FileMediaItem) CallbackMediaItem(androidx.media2.common.CallbackMediaItem) FileMediaItem(androidx.media2.common.FileMediaItem)

Aggregations

CallbackMediaItem (androidx.media2.common.CallbackMediaItem)2 FileMediaItem (androidx.media2.common.FileMediaItem)2 Uri (android.net.Uri)1 Nullable (androidx.annotation.Nullable)1 MediaItem (androidx.media2.common.MediaItem)1 UriMediaItem (androidx.media2.common.UriMediaItem)1