Example usage for android.media MediaMetadata METADATA_KEY_ALBUM_ART_URI

List of usage examples for android.media MediaMetadata METADATA_KEY_ALBUM_ART_URI

Introduction

In this page you can find the example usage for android.media MediaMetadata METADATA_KEY_ALBUM_ART_URI.

Prototype

String METADATA_KEY_ALBUM_ART_URI

To view the source code for android.media MediaMetadata METADATA_KEY_ALBUM_ART_URI.

Click Source Link

Document

The artwork for the album of the media's original source as a Uri formatted String.

Usage

From source file:com.orangesoft.jook.CastPlayback.java

/**
 * Helper method to convert a {@link android.media.MediaMetadata} to a
 * {@link com.google.android.gms.cast.MediaInfo} used for sending media to the receiver app.
 *
 * @param track {@link com.google.android.gms.cast.MediaMetadata}
 * @param customData custom data specifies the local mediaId used by the player.
 *                   @return mediaInfo {@link com.google.android.gms.cast.MediaInfo}
 */// ww w. jav  a  2s  .c  o  m
private static MediaInfo toCastMediaMetadata(MediaMetadata track, JSONObject customData) {
    com.google.android.gms.cast.MediaMetadata metadata = new com.google.android.gms.cast.MediaMetadata(
            com.google.android.gms.cast.MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
    metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_TITLE,
            track.getDescription().getTitle() == null ? "" : track.getDescription().getTitle().toString());
    metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_SUBTITLE,
            track.getDescription().getSubtitle() == null ? ""
                    : track.getDescription().getSubtitle().toString());
    metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_ARTIST,
            track.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST));
    metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_TITLE,
            track.getString(MediaMetadata.METADATA_KEY_ALBUM));
    WebImage image = new WebImage(
            new Uri.Builder().encodedPath(track.getString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI)).build());
    // First image is used by the receiver for showing the audio album art.
    metadata.addImage(image);
    // Second image is used by Cast Companion Library on the full screen activity that is shown
    // when the cast dialog is clicked.
    metadata.addImage(image);

    return new MediaInfo.Builder(track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE))
            .setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setMetadata(metadata).setCustomData(customData).build();
}

From source file:com.example.android.mediabrowserservice.model.MusicProvider.java

private MediaMetadata buildFromJSON(JSONObject json, String basePath) throws JSONException {
    String title = json.getString(JSON_TITLE);
    String album = json.getString(JSON_ALBUM);
    String artist = json.getString(JSON_ARTIST);
    String genre = json.getString(JSON_GENRE);
    String source = json.getString(JSON_SOURCE);
    String iconUrl = json.getString(JSON_IMAGE);
    int trackNumber = json.getInt(JSON_TRACK_NUMBER);
    int totalTrackCount = json.getInt(JSON_TOTAL_TRACK_COUNT);
    int duration = json.getInt(JSON_DURATION) * 1000; // ms

    LogHelper.d(TAG, "Found music track: ", json);

    // Media is stored relative to JSON file
    if (!source.startsWith("http")) {
        source = basePath + source;//from w  ww  .  j a  v a 2 s.  co m
    }
    if (!iconUrl.startsWith("http")) {
        iconUrl = basePath + iconUrl;
    }
    // Since we don't have a unique ID in the server, we fake one using the hashcode of
    // the music source. In a real world app, this could come from the server.
    String id = String.valueOf(source.hashCode());

    // Adding the music source to the MediaMetadata (and consequently using it in the
    // mediaSession.setMetadata) is not a good idea for a real world music app, because
    // the session metadata can be accessed by notification listeners. This is done in this
    // sample for convenience only.
    return new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id)
            .putString(CUSTOM_METADATA_TRACK_SOURCE, source).putString(MediaMetadata.METADATA_KEY_ALBUM, album)
            .putString(MediaMetadata.METADATA_KEY_ARTIST, artist)
            .putLong(MediaMetadata.METADATA_KEY_DURATION, duration)
            .putString(MediaMetadata.METADATA_KEY_GENRE, genre)
            .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, iconUrl)
            .putString(MediaMetadata.METADATA_KEY_TITLE, title)
            .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, trackNumber)
            .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, totalTrackCount).build();
}

From source file:com.chinaftw.music.model.MusicProvider.java

private MediaMetadata buildFromJSON(JSONObject json) throws JSONException {
    String id = String.valueOf(json.getInt(JSON_SONG_ID));
    String title = json.getString(JSON_TITLE);
    String album = json.getJSONObject(JSON_ALBUM).getString(JSON_ALBUM_NAME);
    String albumId = json.getJSONObject(JSON_ALBUM).getString(JSON_ALBUM_ID);
    String artist = json.getJSONArray(JSON_ARTIST).getJSONObject(0).getString(JSON_ARTIST_NAME);
    String artistId = json.getJSONObject(JSON_ALBUM).getString(JSON_ARTIST_ID);
    String imageId = json.getJSONObject(JSON_ALBUM).getString(JSON_ALBUM_IMAGE_ID);
    int duration = json.getInt(JSON_DURATION); // ms

    LogHelper.d(TAG, "Found music track: ", json);

    String source = MusicAPI.getSongUrl(id);
    String imageUri = MusicAPI.getPictureUrl(imageId);

    // Since we don't have a unique ID in the server, we fake one using the hashcode of
    // the music source. In a real world app, this could come from the server.

    // Adding the music source to the MediaMetadata (and consequently using it in the
    // mediaSession.setMetadata) is not a good idea for a real world music app, because
    // the session metadata can be accessed by notification listeners. This is done in this
    // sample for convenience only.
    return new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id)
            .putString(CUSTOM_METADATA_TRACK_SOURCE, source).putString(MediaMetadata.METADATA_KEY_ALBUM, album)
            .putString(MediaMetadata.METADATA_KEY_ARTIST, artist)
            .putLong(MediaMetadata.METADATA_KEY_DURATION, duration)
            .putString(MediaMetadata.METADATA_KEY_GENRE, "BILLBOARD") //TODO
            .putString(MediaMetadata.METADATA_KEY_TITLE, title)
            .putString(MediaMetadata.METADATA_KEY_ART_URI, imageUri)
            .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, imageUri)
            .putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, imageUri).build();
}

From source file:robert843.o2.pl.player.model.MusicProvider.java

private MediaMetadata buildFromJSON(String ytId)
        throws JSONException, ParserConfigurationException, IOException {
    String title = "";
    String artist = "";
    String source = "";
    String iconUrl = "";
    String site = "yt";
    int duration = 0; // ms

    LogHelper.d(TAG, "Found music track: ", ytId);

    // Media is stored relative to JSON file
    if (site.contains("yt")) {
        MovieParser parser = new MovieParser(ytId);
        parser.parse();// www  . j a  va2s .  c  o m
        source = "" + parser.getUrl();
        duration = parser.getLength() * 1000;
        iconUrl = parser.getAlbumUrl();
        System.out.println(iconUrl);
        title = parser.getTitle();
        artist = parser.getChanelName();
    }

    // Since we don't have a unique ID in the server, we fake one using the hashcode of
    // the music source. In a real world app, this could come from the server.
    String id = String.valueOf(source.hashCode());

    // Adding the music source to the MediaMetadata (and consequently using it in the
    // mediaSession.setMetadata) is not a good idea for a real world music app, because
    // the session metadata can be accessed by notification listeners. This is done in this
    // sample for convenience only.
    return new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id)
            // .putString(CUSTOM_METADATA_TRACK_SOURCE, source)
            .putString(MediaMetadata.METADATA_KEY_ARTIST, artist).putString("id", ytId)
            .putLong(MediaMetadata.METADATA_KEY_DURATION, duration)
            .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, iconUrl)
            .putString(MediaMetadata.METADATA_KEY_TITLE, title).build();
}

From source file:de.rwth_aachen.comsys.audiosync.model.MusicProvider.java

private void createLocal(String file) {
    MediaMetadata item = new MediaMetadata.Builder()
            .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, LOCAL_PREFIX + file)
            .putString(CUSTOM_METADATA_TRACK_SOURCE, "https://dl.dropboxusercontent.com/u/58908793/" + file)
            .putString(CUSTOM_METADATA_ASSET_FILE, file).putString(MediaMetadata.METADATA_KEY_ALBUM, "Demo")
            .putString(MediaMetadata.METADATA_KEY_ARTIST, "Simon G")
            .putLong(MediaMetadata.METADATA_KEY_DURATION, 304000)
            .putString(MediaMetadata.METADATA_KEY_GENRE, "Testing")
            .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI,
                    "https://upload.wikimedia.org/wikipedia/commons/0/02/Metr%C3%B3nomo_digital_Korg_MA-30.jpg")
            .putString(MediaMetadata.METADATA_KEY_TITLE, file)
            .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, 1)
            .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, 1).build();

    String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
    mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
}