Example usage for android.media MediaDescription getExtras

List of usage examples for android.media MediaDescription getExtras

Introduction

In this page you can find the example usage for android.media MediaDescription getExtras.

Prototype

public @Nullable Bundle getExtras() 

Source Link

Document

Returns any extras that were added to the description.

Usage

From source file:org.opensilk.video.data.MediaDescriptionUtil.java

public static MediaDescription.Builder newBuilder(MediaDescription description) {
    MediaDescription.Builder bob = new MediaDescription.Builder().setIconUri(description.getIconUri())
            .setMediaId(description.getMediaId()).setExtras(description.getExtras())
            .setSubtitle(description.getSubtitle()).setTitle(description.getTitle())
            .setDescription(description.getDescription());
    if (VersionUtils.hasApi23()) {
        bob.setMediaUri(description.getMediaUri());
    }//from  w  w  w.  java 2 s  .  c o  m
    return bob;
}

From source file:org.opensilk.video.data.MediaMetaExtras.java

public static MediaMetaExtras from(MediaDescription description) {
    Bundle b = description.getExtras();
    if (b == null) {
        throw new RuntimeException(String.format(Locale.US,
                "Description [%s] did not have extras this is an error!!", description.getTitle()));
    }// w  w  w.j  a va 2s.c om
    return new MediaMetaExtras(b);
}

From source file:org.opensilk.video.data.VideosProviderClient.java

public boolean insertMedia(MediaBrowser.MediaItem mediaItem) {
    ContentValues cv = new ContentValues(10);
    MediaDescription description = mediaItem.getDescription();
    MediaMetaExtras metaExtras = MediaMetaExtras.from(description.getExtras());
    Uri mediaUri = MediaDescriptionUtil.getMediaUri(description);
    cv.put("_display_name", metaExtras.getMediaTitle());
    String descriptionTitle = description.getTitle() != null ? description.getTitle().toString() : null;
    cv.put("_title", descriptionTitle);
    String descriptionSubtitle = description.getSubtitle() != null ? description.getSubtitle().toString()
            : null;// w  ww  .  j  ava  2s  .  co  m
    cv.put("_subtitle", descriptionSubtitle);

    cv.put("parent_media_uri", metaExtras.getParentUri().toString());
    cv.put("server_id", metaExtras.getServerId());
    cv.put("media_category", metaExtras.getMediaType());
    if (description.getIconUri() != null) {
        cv.put("artwork_uri", description.getIconUri().toString());
    }
    cv.put("is_indexed", metaExtras.isIndexed() ? 1 : 0);
    //Not setting last_played or duration service does that

    if (metaExtras.isTvEpisode()) {
        tvdb().onInsertMedia(mediaItem, cv);
    } else if (metaExtras.isMovie()) {
        moviedb().onInsertMedia(mediaItem, cv);
    }

    try {
        int num = mResolver.update(mUris.media(), cv, "media_uri=?", new String[] { mediaUri.toString() });
        if (num > 0) {
            Timber.d("Updated %d rows for %s", num, metaExtras.getMediaTitle());
            return true;
        }
        cv.put("media_uri", mediaUri.toString());
        cv.put("date_added", System.currentTimeMillis());
        return mResolver.insert(mUris.media(), cv) != null;
    } catch (SQLiteException e) {
        Timber.w(e, "Failed updating %s values=%s", metaExtras.getMediaTitle(), cv.toString());
        return false;
    }
}