Пример #1
0
 /**
  * This method puts {@link Item}s from a {@link Iterable} into a {@link MediaMetadata.Builder}.
  *
  * @param metadata The {@code MediaMetadata.Builder} object to put the Items into.
  * @param key The key to store the items in.
  * @param response The response to iterate over to put into the metadata builder.
  */
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 private static void putResponseObject(
     final MediaMetadata.Builder metadata,
     final String key,
     final Iterable<? extends Item<?>> response) {
   for (final Item<?> item : response) {
     metadata.putString(key, item.getName());
   }
 }
  private void updateMetadata(final Movie movie) {
    final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();

    String title = movie.getTitle().replace("_", " -");

    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, movie.getDescription());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, movie.getCardImageUrl());

    // And at minimum the title and artist for legacy support
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, movie.getStudio());

    Glide.with(this)
        .load(Uri.parse(movie.getCardImageUrl()))
        .asBitmap()
        .into(
            new SimpleTarget<Bitmap>(500, 500) {
              @Override
              public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
                mSession.setMetadata(metadataBuilder.build());
              }
            });
  }
Пример #3
0
  /**
   * Adds metadata from the current track to a {@code MediaMetadata.Builder} object.
   *
   * @param metadata The constructed {@code MediaMetadata.Builder} object to add the current track
   *     metadata to.
   */
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public void getMediaMetadata(final MediaMetadata.Builder metadata) {
    final Album album = getAlbum();

    metadata
        .putLong(MediaMetadata.METADATA_KEY_DISC_NUMBER, (long) getDisc())
        .putLong(MediaMetadata.METADATA_KEY_DURATION, getTime())
        .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, (long) getTotalTracks())
        .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, (long) getTrack())
        .putLong(MediaMetadata.METADATA_KEY_YEAR, album.getDate())
        .putString(MediaMetadata.METADATA_KEY_ALBUM, album.getName())
        .putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName())
        .putString(MediaMetadata.METADATA_KEY_ARTIST, getArtistName())
        .putString(MediaMetadata.METADATA_KEY_COMPOSER, getComposerName())
        .putString(MediaMetadata.METADATA_KEY_DATE, Long.toString(getDate()))
        .putString(MediaMetadata.METADATA_KEY_TITLE, getTitle());

    putResponseObject(metadata, MediaMetadata.METADATA_KEY_GENRE, getGenres());
  }