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.torrenttunes.android.CastPlayback.java

/**
 * Helper method to convert a {@link MediaMetadataCompat} 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}
 *//* www  .  j  a va 2  s.  c o m*/
private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) {

    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
    mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.getDescription().getTitle().toString());
    mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle().toString());
    mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST,
            track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST));
    mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE,
            track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
    WebImage image = new WebImage(new Uri.Builder()
            .encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build());
    // First image is used by the receiver for showing the audio album art.
    mediaMetadata.addImage(image);
    // Second image is used by Cast Companion Library on the full screen activity that is shown
    // when the cast dialog is clicked.
    mediaMetadata.addImage(image);

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

From source file:com.appdevper.mediaplayer.app.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}
 *///www  . j  av  a 2  s  .com
private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) {
    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
    mediaMetadata.putString(MediaMetadata.KEY_TITLE,
            track.getDescription().getTitle() == null ? "" : track.getDescription().getTitle().toString());
    mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle() == null ? ""
            : track.getDescription().getSubtitle().toString());
    mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST,
            track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST));
    mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE,
            track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
    WebImage image = new WebImage(new Uri.Builder()
            .encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build());
    // First image is used by the receiver for showing the audio album art.
    mediaMetadata.addImage(image);
    // Second image is used by Cast Companion Library on the full screen activity that is shown
    // when the cast dialog is clicked.
    mediaMetadata.addImage(image);

    //noinspection ResourceType
    return new MediaInfo.Builder(track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE))
            .setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setMetadata(mediaMetadata).setCustomData(customData).build();
}

From source file:com.classiqo.nativeandroid_32bitz.playback.CastPlayback.java

private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) {
    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);

    mediaMetadata.putString(MediaMetadata.KEY_TITLE,
            track.getDescription().getTitle() == null ? "" : track.getDescription().getTitle().toString());

    mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle() == null ? ""
            : track.getDescription().getSubtitle().toString());

    mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST,
            track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST));

    mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE,
            track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));

    WebImage image = new WebImage(new Uri.Builder()
            .encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build());

    mediaMetadata.addImage(image);/*from   w  w w  .  j  a  v a2 s . com*/
    mediaMetadata.addImage(image);

    //noinspection ResourceType
    return new MediaInfo.Builder(track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE))
            .setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setMetadata(mediaMetadata).setCustomData(customData).build();
}

From source file:com.example.chu.googleplaylibrary.playback.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}
 *//*w w w . j av  a 2  s  .co  m*/
private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) {
    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
    if (track != null) {
        mediaMetadata.putString(MediaMetadata.KEY_TITLE,
                track.getDescription().getTitle() == null ? "" : track.getDescription().getTitle().toString());
        mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle() == null ? ""
                : track.getDescription().getSubtitle().toString());
        mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST,
                track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST));
        mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE,
                track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
    }
    WebImage image = new WebImage(new Uri.Builder()
            .encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build());
    // First image is used by the receiver for showing the audio album art.
    mediaMetadata.addImage(image);
    // Second image is used by Cast Companion Library on the full screen activity that is shown
    // when the cast dialog is clicked.
    mediaMetadata.addImage(image);

    //noinspection ResourceType
    return new MediaInfo.Builder(track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE))
            .setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setMetadata(mediaMetadata).setCustomData(customData).build();
}

From source file:org.opensilk.music.ui3.nowplaying.QueueScreenPresenter.java

void subscribeBroadcasts() {
    if (isSubscribed(broadcastSubscriptions)) {
        return;/*from   www  .j a v  a  2  s  .  co  m*/
    }
    Subscription s = playbackController.subscribeMetaChanges(new Action1<MediaMetadataCompat>() {
        @Override
        public void call(MediaMetadataCompat mediaMetadata) {
            String track = mediaMetadata.getString(METADATA_KEY_TITLE);
            String artist = mediaMetadata.getString(METADATA_KEY_ARTIST);
            String id = mediaMetadata.getString(METADATA_KEY_MEDIA_ID);
            if (hasView()) {
                getView().mTitle.setText(track);
                getView().mSubTitle.setText(artist);
                getView().getAdapter().setActiveItem(id);
            }
        }
    });
    Subscription s1 = playbackController.subscribePlayStateChanges(new Action1<PlaybackStateCompat>() {
        @Override
        public void call(PlaybackStateCompat playbackState) {
            if (hasView()) {
                getView().getAdapter().setPlaying(MainPresenter.isPlaying(playbackState));
            }
        }
    });
    Subscription s2 = playbackController
            .subscribeQueueChanges(new Action1<List<MediaSessionCompat.QueueItem>>() {
                @Override
                public void call(List<MediaSessionCompat.QueueItem> queueItems) {
                    if (hasView()) {
                        getView().getAdapter().replaceAll(queueItems);
                    }
                }
            });
    broadcastSubscriptions = new CompositeSubscription(s, s1, s2);
}

From source file:com.appdevper.mediaplayer.adater.MediaItemViewHolder.java

static View setupView(Activity activity, View convertView, ViewGroup parent, MediaMetadataCompat item,
        int state) {

    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(activity);
    }// w ww .ja va2s.co m

    MediaItemViewHolder holder;

    Integer cachedState = STATE_INVALID;

    if (convertView == null) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.media_list_item, parent, false);
        holder = new MediaItemViewHolder();
        holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
        holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
        holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
        convertView.setTag(holder);
    } else {
        holder = (MediaItemViewHolder) convertView.getTag();
        cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache);
    }

    holder.mTitleView.setText(item.getString(MediaMetadataCompat.METADATA_KEY_TITLE));
    holder.mDescriptionView.setText(item.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));

    // If the state of convertView is different, we need to adapt the view to the
    // new state.
    if (cachedState == null || cachedState != state) {
        switch (state) {
        case STATE_PLAYABLE:
            Drawable pauseDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_play_arrow_black_36dp);
            DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
            holder.mImageView.setImageDrawable(pauseDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        case STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(activity,
                    R.drawable.ic_equalizer_white_36dp);
            DrawableCompat.setTintList(animation, sColorStatePlaying);
            holder.mImageView.setImageDrawable(animation);
            holder.mImageView.setVisibility(View.VISIBLE);
            animation.start();
            break;
        case STATE_PAUSED:
            Drawable playDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_equalizer1_white_36dp);
            DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
            holder.mImageView.setImageDrawable(playDrawable);
            holder.mImageView.setVisibility(View.VISIBLE);
            break;
        default:
            holder.mImageView.setVisibility(View.GONE);
        }
        convertView.setTag(R.id.tag_mediaitem_state_cache, state);
    }

    return convertView;
}

From source file:com.phearom.um.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
    String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(),
            MEDIA_ID_MUSICS_BY_GENRE, genre);
    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.radiofarda.istgah.model.MusicProvider.java

private synchronized void retrieveMedia() {
    try {//from   w w  w  .  j  av  a2  s .  c  o m
        if (mCurrentState == State.NON_INITIALIZED) {
            mCurrentState = State.INITIALIZING;

            Iterator<MediaMetadataCompat> tracks = mSource.iterator();
            while (tracks.hasNext()) {
                MediaMetadataCompat item = tracks.next();
                String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID);
                mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
            }
            mCurrentState = State.INITIALIZED;
        }
    } 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;
        }
    }
}

From source file:com.classiqo.nativeandroid_32bitz.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
    String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(),
            MEDIA_ID_MUSICS_BY_GENRE, genre);
    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.phearom.um.model.MusicProvider.java

private void retrieveMedia(Iterator<MediaMetadataCompat> tracks) {
    try {/*from  w  w w  .j a va2s  .c om*/
        if (mCurrentState == State.NON_INITIALIZED) {
            mCurrentState = State.INITIALIZING;
            while (tracks.hasNext()) {
                MediaMetadataCompat item = tracks.next();
                String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID);
                mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
            }
            buildListsByGenre();
            mCurrentState = State.INITIALIZED;
        }
    } finally {
        if (mCurrentState != State.INITIALIZED) {
            mCurrentState = State.NON_INITIALIZED;
        }
    }
}