List of usage examples for android.support.v4.media MediaMetadataCompat containsKey
public boolean containsKey(String key)
From source file:rocks.stalin.android.app.playback.RemotePlayback.java
@Override public void play(QueueItem item) { mPlayOnFocusGain = true;//from w w w . ja va 2 s. c o m tryToGetAudioFocus(); registerAudioNoisyReceiver(); String mediaId = item.getDescription().getMediaId(); boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId); if (mediaHasChanged) { mCurrentPosition = 0; mCurrentMediaId = mediaId; } if (mState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mediaPlayer != null) { configMediaPlayerState(); } else { mState = PlaybackStateCompat.STATE_STOPPED; relaxResources(false); // release everything except MediaPlayer MediaMetadataCompat track = mMusicProvider .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId())); String source = null; Uri uriSource = null; //noinspection ResourceType if (track.containsKey(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE)) { source = track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE); if (source != null) { source = source.replaceAll(" ", "%20"); // Escape spaces for URLs } } else { uriSource = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, Long.parseLong(track.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID))); } try { createMediaPlayerIfNeeded(); mState = PlaybackStateCompat.STATE_BUFFERING; mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); if (uriSource != null) { mediaPlayer.setDataSource(mContext, uriSource); } else { mediaPlayer.setDataSource(source); // If we are streaming from the internet, we want to hold a // Wifi lock, which prevents the Wifi radio from going to // sleep while the song is playing. mWifiLock.acquire(); } // Starts preparing the media player in the background. When // it's done, it will call our OnPreparedListener (that is, // the onPrepared() method on this class, since we set the // listener to 'this'). Until the media player is prepared, // we *cannot* call start() on it! mediaPlayer.prepareAsync(); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } } catch (IOException ex) { LogHelper.e(TAG, ex, "Exception playing song"); if (mCallback != null) { mCallback.onError(ex.getMessage()); } } } }