public class

CallbackMediaItem

extends MediaItem

 java.lang.Object

androidx.versionedparcelable.CustomVersionedParcelable

androidx.media2.common.MediaItem

↳androidx.media2.common.CallbackMediaItem

Gradle dependencies

compile group: 'androidx.media2', name: 'media2-common', version: '1.2.1'

  • groupId: androidx.media2
  • artifactId: media2-common
  • version: 1.2.1

Artifact androidx.media2:media2-common:1.2.1 it located at Google repository (https://maven.google.com/)

Overview

Structure for media item descriptor for DataSourceCallback.

Users should use CallbackMediaItem.Builder to create CallbackMediaItem.

You cannot directly send this object across the process through ParcelUtils. See MediaItem for detail.

Summary

Fields
from MediaItemPOSITION_UNKNOWN
Methods
public DataSourceCallbackgetDataSourceCallback()

Return the DataSourceCallback that implements the callback for the data source of this media item.

from MediaItemaddOnMetadataChangedListener, getEndPosition, getMediaId, getMetadata, getStartPosition, onPreParceling, removeOnMetadataChangedListener, setMetadata, toString
from CustomVersionedParcelableonPostParceling
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Methods

public DataSourceCallback getDataSourceCallback()

Return the DataSourceCallback that implements the callback for the data source of this media item.

Returns:

the DataSourceCallback that implements the callback for the data source of this media item,

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.media2.common;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Preconditions;
import androidx.versionedparcelable.ParcelUtils;

/**
 * Structure for media item descriptor for {@link DataSourceCallback}.
 * <p>
 * Users should use {@link Builder} to create {@link CallbackMediaItem}.
 * <p>
 * You cannot directly send this object across the process through {@link ParcelUtils}. See
 * {@link MediaItem} for detail.
 *
 * @see MediaItem
 */
public class CallbackMediaItem extends MediaItem {
    private final DataSourceCallback mDataSourceCallback;

    CallbackMediaItem(Builder builder) {
        super(builder);
        mDataSourceCallback = builder.mDataSourceCallback;
    }

    /**
     * Return the DataSourceCallback that implements the callback for the data source of this media
     * item.
     *
     * @return the DataSourceCallback that implements the callback for the data source of this
     *         media item,
     */
    public @NonNull DataSourceCallback getDataSourceCallback() {
        return mDataSourceCallback;
    }

    /**
     * This Builder class simplifies the creation of a {@link CallbackMediaItem} object.
     */
    public static final class Builder extends MediaItem.Builder {

        @SuppressWarnings("WeakerAccess") /* synthetic access */
        DataSourceCallback mDataSourceCallback;

        /**
         * Creates a new Builder object.
         * @param dsc2 the DataSourceCallback for the media you want to play
         */
        public Builder(@NonNull DataSourceCallback dsc2) {
            Preconditions.checkNotNull(dsc2);
            mDataSourceCallback = dsc2;
        }

        // Override just to change return type.
        @Override
        @NonNull
        public Builder setMetadata(@Nullable MediaMetadata metadata) {
            return (Builder) super.setMetadata(metadata);
        }

        // Override just to change return type.
        @Override
        @NonNull
        public Builder setStartPosition(long position) {
            return (Builder) super.setStartPosition(position);
        }

        // Override just to change return type.
        @Override
        @NonNull
        public Builder setEndPosition(long position) {
            return (Builder) super.setEndPosition(position);
        }

        /**
         * @return A new CallbackMediaItem with values supplied by the Builder.
         */
        @Override
        @NonNull
        public CallbackMediaItem build() {
            return new CallbackMediaItem(this);
        }
    }
}