Example usage for android.media MediaDescription getTitle

List of usage examples for android.media MediaDescription getTitle

Introduction

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

Prototype

public @Nullable CharSequence getTitle() 

Source Link

Document

Returns a title suitable for display or null.

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());
    }/* w w w. j  a v  a 2  s. c o  m*/
    return bob;
}

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

public static String getMediaTitle(MediaDescription description) {
    MediaMetaExtras metaExtras = MediaMetaExtras.from(description);
    String mediaTitle = metaExtras.getMediaTitle();
    if (StringUtils.isEmpty(mediaTitle)) {
        Timber.e("MediaTitle not set in %s", MediaDescriptionUtil.getMediaUri(description));
        mediaTitle = description.getTitle() != null ? description.getTitle().toString() : "";
    }/*from   w  w  w .  j  a  va  2  s . c  o  m*/
    return mediaTitle;
}

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

public static String toString(MediaDescription description) {
    return new ToStringBuilder(description).append("title", description.getTitle())
            .append("mediaId", description.getMediaId()).append("mediaUri", getMediaUri(description))
            .append("mediaTitle", getMediaTitle(description)).build();

}

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

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

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

public static VideoDescInfo from(MediaDescription description) {
    return builder().setTitle(description.getTitle()).setSubtitle(description.getSubtitle())
            .setOverview(description.getDescription()).build();
}

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;/*from  w  w w.ja v  a  2  s.c o  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;
    }
}

From source file:org.opensilk.video.playback.PlaybackService.java

void updateMetadata() {
    assertCreated();//w  w  w . jav  a2 s .c  om
    final Media media = mMediaPlayer.getMedia();
    final MediaBrowser.MediaItem mediaItem = mDbClient.getMedia(media.getUri());

    final MediaMetadata.Builder b = new MediaMetadata.Builder();
    CharSequence title;
    Uri artworkUri = null;
    long duration;
    if (mediaItem != null) {
        MediaDescription description = mediaItem.getDescription();
        title = description.getTitle();
        b.putText(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
        b.putText(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, description.getSubtitle());
        if (description.getIconUri() != null) {
            b.putText(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, description.getIconUri().toString());
            artworkUri = description.getIconUri();
        }
        MediaMetaExtras metaExtras = MediaMetaExtras.from(description);
        b.putText(MediaMetadata.METADATA_KEY_TITLE, metaExtras.getMediaTitle());
        duration = metaExtras.getDuration();
    } else {
        title = media.getMeta(Media.Meta.Title);
        b.putText(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
        String artworkUrl = media.getMeta(Media.Meta.ArtworkURL);
        if (!StringUtils.isEmpty(artworkUrl)) {
            b.putText(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, artworkUrl);
            artworkUri = Uri.parse(artworkUrl);
        }
        duration = mMediaPlayer.getLength();
    }
    b.putLong(MediaMetadata.METADATA_KEY_DURATION, duration);
    if (artworkUri != null) {
        RequestOptions options = new RequestOptions().fitCenter(mContext);
        FutureTarget<Bitmap> futureTarget = Glide.with(mContext).asBitmap().apply(options).load(artworkUri)
                .submit();
        try {
            Bitmap bitmap = futureTarget.get(5000, TimeUnit.MILLISECONDS);
            b.putBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON, bitmap);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            //pass
        }
    }
    mMediaSession.setMetadata(b.build());
    mMediaSession.setSessionActivity(makeActivityIntent(mediaItem));
}