/*
 * Copyright 2018 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 android.media;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.media.update.ApiLoader;
import android.media.update.MediaItem2Provider;
import android.os.Bundle;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@hide A class with information on a single media item with the metadata information. Media item are application dependent so we cannot guarantee that they contain the right values.

When it's sent to a controller or browser, it's anonymized and data descriptor wouldn't be sent.

This object isn't a thread safe.

/** * @hide * A class with information on a single media item with the metadata information. * Media item are application dependent so we cannot guarantee that they contain the right values. * <p> * When it's sent to a controller or browser, it's anonymized and data descriptor wouldn't be sent. * <p> * This object isn't a thread safe. */
public class MediaItem2 {
@hide
/** @hide */
@Retention(RetentionPolicy.SOURCE) @IntDef(flag=true, value = { FLAG_BROWSABLE, FLAG_PLAYABLE }) public @interface Flags { }
Flag: Indicates that the item has children of its own.
/** * Flag: Indicates that the item has children of its own. */
public static final int FLAG_BROWSABLE = 1 << 0;
Flag: Indicates that the item is playable.

The id of this item may be passed to MediaController2.playFromMediaId(String, Bundle)

/** * Flag: Indicates that the item is playable. * <p> * The id of this item may be passed to * {@link MediaController2#playFromMediaId(String, Bundle)} */
public static final int FLAG_PLAYABLE = 1 << 1; private final MediaItem2Provider mProvider;
Create a new media item
@hide
/** * Create a new media item * @hide */
public MediaItem2(MediaItem2Provider provider) { mProvider = provider; }
@hide
/** * @hide */
public MediaItem2Provider getProvider() { return mProvider; }
Return this object as a bundle to share between processes.
Returns:a new bundle instance
/** * Return this object as a bundle to share between processes. * * @return a new bundle instance */
public Bundle toBundle() { return mProvider.toBundle_impl(); } public static MediaItem2 fromBundle(Bundle bundle) { return ApiLoader.getProvider().fromBundle_MediaItem2(bundle); } public String toString() { return mProvider.toString_impl(); }
Gets the flags of the item.
/** * Gets the flags of the item. */
public @Flags int getFlags() { return mProvider.getFlags_impl(); }
Returns whether this item is browsable.
See Also:
  • FLAG_BROWSABLE
/** * Returns whether this item is browsable. * @see #FLAG_BROWSABLE */
public boolean isBrowsable() { return mProvider.isBrowsable_impl(); }
Returns whether this item is playable.
See Also:
  • FLAG_PLAYABLE
/** * Returns whether this item is playable. * @see #FLAG_PLAYABLE */
public boolean isPlayable() { return mProvider.isPlayable_impl(); }
Set a metadata. If the metadata is not null, its id should be matched with this instance's media id.
Params:
  • metadata – metadata to update
/** * Set a metadata. If the metadata is not null, its id should be matched with this instance's * media id. * * @param metadata metadata to update */
public void setMetadata(@Nullable MediaMetadata2 metadata) { mProvider.setMetadata_impl(metadata); }
Returns the metadata of the media.
/** * Returns the metadata of the media. */
public @Nullable MediaMetadata2 getMetadata() { return mProvider.getMetadata_impl(); }
Returns the media id for this item.
/** * Returns the media id for this item. */
public @NonNull String getMediaId() { return mProvider.getMediaId_impl(); }
Return the DataSourceDesc

Can be null if the MediaItem2 came from another process and anonymized

Returns:data source descriptor
/** * Return the {@link DataSourceDesc} * <p> * Can be {@code null} if the MediaItem2 came from another process and anonymized * * @return data source descriptor */
public @Nullable DataSourceDesc getDataSourceDesc() { return mProvider.getDataSourceDesc_impl(); } @Override public boolean equals(Object obj) { return mProvider.equals_impl(obj); }
Build MediaItem2
/** * Build {@link MediaItem2} */
public static final class Builder { private final MediaItem2Provider.BuilderProvider mProvider;
Constructor for Builder
Params:
  • flags –
/** * Constructor for {@link Builder} * * @param flags */
public Builder(@Flags int flags) { mProvider = ApiLoader.getProvider().createMediaItem2Builder(this, flags); }
Set the media id of this instance. null for unset.

Media id is used to identify a media contents between session and controller.

If the metadata is set with the setMetadata(MediaMetadata2) and it has media id, id from setMediaId(String) will be ignored and metadata's id will be used instead. If the id isn't set neither by setMediaId(String) nor setMetadata(MediaMetadata2), id will be automatically generated.

Params:
  • mediaId – media id
Returns:this instance for chaining
/** * Set the media id of this instance. {@code null} for unset. * <p> * Media id is used to identify a media contents between session and controller. * <p> * If the metadata is set with the {@link #setMetadata(MediaMetadata2)} and it has * media id, id from {@link #setMediaId(String)} will be ignored and metadata's id will be * used instead. If the id isn't set neither by {@link #setMediaId(String)} nor * {@link #setMetadata(MediaMetadata2)}, id will be automatically generated. * * @param mediaId media id * @return this instance for chaining */
public Builder setMediaId(@Nullable String mediaId) { return mProvider.setMediaId_impl(mediaId); }
Set the metadata of this instance. null for unset.

If the metadata is set with the setMetadata(MediaMetadata2) and it has media id, id from setMediaId(String) will be ignored and metadata's id will be used instead. If the id isn't set neither by setMediaId(String) nor setMetadata(MediaMetadata2), id will be automatically generated.

Params:
  • metadata – metadata
Returns:this instance for chaining
/** * Set the metadata of this instance. {@code null} for unset. * <p> * If the metadata is set with the {@link #setMetadata(MediaMetadata2)} and it has * media id, id from {@link #setMediaId(String)} will be ignored and metadata's id will be * used instead. If the id isn't set neither by {@link #setMediaId(String)} nor * {@link #setMetadata(MediaMetadata2)}, id will be automatically generated. * * @param metadata metadata * @return this instance for chaining */
public Builder setMetadata(@Nullable MediaMetadata2 metadata) { return mProvider.setMetadata_impl(metadata); }
Set the data source descriptor for this instance. null for unset.
Params:
  • dataSourceDesc – data source descriptor
Returns:this instance for chaining
/** * Set the data source descriptor for this instance. {@code null} for unset. * * @param dataSourceDesc data source descriptor * @return this instance for chaining */
public Builder setDataSourceDesc(@Nullable DataSourceDesc dataSourceDesc) { return mProvider.setDataSourceDesc_impl(dataSourceDesc); }
Build MediaItem2.
Returns:a new MediaItem2.
/** * Build {@link MediaItem2}. * * @return a new {@link MediaItem2}. */
public MediaItem2 build() { return mProvider.build_impl(); } } }