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

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

Introduction

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

Prototype

public String getString(@TextKey String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.murati.oszk.audiobook.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createEbookHeader(String ebook, Resources resources) {
    //TODO: canonize ebook mediaid and title conversion
    if (ebook.startsWith(MEDIA_ID_BY_EBOOK)) {
        ebook = getCategoryValueFromMediaID(ebook);
    }/*from w w  w .  j  a v  a 2 s . c o  m*/

    MediaMetadataCompat metadata = getTracksByEbook(ebook).iterator().next();

    //TODO: fix header notation
    MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
            .setMediaId(createMediaID(MEDIA_ID_EBOOK_HEADER, MEDIA_ID_BY_EBOOK, ebook)).setTitle(ebook)
            .setSubtitle(metadata.getString(MediaMetadataCompat.METADATA_KEY_WRITER))
            //TODO: Fix Album art
            .setIconUri(Uri.parse(metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)))
            //TODO: fix default image
            // .setIconBitmap(BitmapHelper.convertDrawabletoUri(R.drawable.ic_navigate_books))
            .build();
    return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE);
}

From source file:com.murati.oszk.audiobook.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createTrackItem(MediaMetadataCompat metadata) {
    // Since mediaMetadata fields are immutable, we need to create a copy, so we
    // can set a hierarchy-aware mediaID. We will need to know the media hierarchy
    // when we get a onPlayFromMusicID call, so we can create the proper queue based
    // on where the music was selected from (by artist, by genre, random, etc)
    String ebook = metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM);
    String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(),
            MEDIA_ID_BY_EBOOK, ebook);//from   w  w  w . j av  a 2  s.com
    MediaMetadataCompat copy = new MediaMetadataCompat.Builder(metadata)
            .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();
    return new MediaBrowserCompat.MediaItem(copy.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);

}

From source file:com.torrenttunes.android.MusicService.java

private void setCustomAction(PlaybackStateCompat.Builder stateBuilder) {
    MediaMetadataCompat currentMusic = getCurrentPlayingMusic();
    if (currentMusic != null) {
        // Set appropriate "Favorite" icon on Custom action:
        String musicId = currentMusic.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID);
        int favoriteIcon = R.drawable.ic_star_off;
        if (mMusicProvider.isFavorite(musicId)) {
            favoriteIcon = R.drawable.ic_star_on;
        }//from   w w w .  java 2  s.  c  om
        LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ", musicId,
                " current favorite=", mMusicProvider.isFavorite(musicId));
        //            stateBuilder.addCustomAction(CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite),
        //                    favoriteIcon);
    }
}

From source file:com.whitecloud.ron.musicplayer.model.MusicProvider.java

public ArrayList<Song> getTopTracks(String spotifyId) {
    try {//w  w w .  j  av  a 2 s  .com
        if (mCurrentState == State.NON_INITIALIZED) {
            mCurrentState = State.INITIALIZING;
            SpotifyApi api = new SpotifyApi();
            SpotifyService spotify = api.getService();
            Tracks tracks = spotify.getArtistTopTrack(spotifyId, "CA");
            List<Track> trackList = tracks.tracks;

            if (trackList != null) {
                for (int j = 0; j < trackList.size(); j++) {
                    Track track = trackList.get(j);
                    MediaMetadataCompat item = new MediaMetadataCompat.Builder()
                            .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, track.id)
                            //                                 .putString(CUSTOM_METADATA_TRACK_SOURCE, track.preview_url)
                            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, track.album.name)
                            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, track.artists.get(0).name)
                            .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, track.duration_ms)
                            .putString(MediaMetadataCompat.METADATA_KEY_GENRE, track.type)
                            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI,
                                    track.album.images.get(0).url)
                            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, track.name)
                            .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, track.track_number)
                            .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, trackList.size()).build();
                    String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID);
                    mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
                    mMusicSourceList.put(musicId, track.preview_url);
                    mSongs.add(new Song(track.preview_url, track.name, track.album.name,
                            track.album.images.get(0).url, track.album.images.get(1).url));
                }
                buildListsByGenre();
            }
            mCurrentState = State.INITIALIZED;
        }
    } catch (RetrofitError e) {
        LogHelper.e(TAG, e, "Could not retrieve music list");
    } finally {
        if (mCurrentState != State.INITIALIZED) {
            // Something bad happened, so we reset state to NON_INITIALIZED to allow
            // retries (eg if the network connection is temporary unavailable)
            mCurrentState = State.NON_INITIALIZED;
        }

        return (ArrayList) mSongs;

    }
}