Example usage for android.support.v4.media MediaMetadataCompat getBundle

List of usage examples for android.support.v4.media MediaMetadataCompat getBundle

Introduction

In this page you can find the example usage for android.support.v4.media MediaMetadataCompat getBundle.

Prototype

public Bundle getBundle() 

Source Link

Document

Gets a copy of the bundle for this metadata object.

Usage

From source file:androidx.media.MediaUtils2.java

/**
 * Creates a {@link MediaMetadata2} from the {@link MediaMetadataCompat}.
 *
 * @param metadataCompat A {@link MediaMetadataCompat} object.
 * @return The newly created {@link MediaMetadata2} object.
 *//*from w w  w . ja v a 2 s.com*/
MediaMetadata2 createMediaMetadata2(MediaMetadataCompat metadataCompat) {
    if (metadataCompat == null) {
        return null;
    }
    return new MediaMetadata2(metadataCompat.getBundle());
}

From source file:androidx.media.MediaUtils2.java

/**
 * Creates a {@link MediaMetadataCompat} from the {@link MediaMetadata2}.
 *
 * @param metadata2 A {@link MediaMetadata2} object.
 * @return The newly created {@link MediaMetadataCompat} object.
 *//*w w  w .j a va2  s .co  m*/
MediaMetadataCompat createMediaMetadataCompat(MediaMetadata2 metadata2) {
    if (metadata2 == null) {
        return null;
    }

    MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();

    List<String> skippedKeys = new ArrayList<>();
    Bundle bundle = metadata2.toBundle();
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        if (value instanceof CharSequence) {
            builder.putText(key, (CharSequence) value);
        } else if (value instanceof Rating2) {
            builder.putRating(key, createRatingCompat((Rating2) value));
        } else if (value instanceof Bitmap) {
            builder.putBitmap(key, (Bitmap) value);
        } else if (value instanceof Long) {
            builder.putLong(key, (Long) value);
        } else {
            // There is no 'float' or 'bundle' type in MediaMetadataCompat.
            skippedKeys.add(key);
        }
    }

    MediaMetadataCompat result = builder.build();
    for (String key : skippedKeys) {
        Object value = bundle.get(key);
        if (value instanceof Float) {
            // Compatibility for MediaMetadata2.Builder.putFloat()
            result.getBundle().putFloat(key, (Float) value);
        } else if (METADATA_KEY_EXTRAS.equals(value)) {
            // Compatibility for MediaMetadata2.Builder.setExtras()
            result.getBundle().putBundle(key, (Bundle) value);
        }
    }
    return result;
}