Java Code Examples for android.support.v4.media.MediaMetadataCompat#getString()
The following examples show how to use
android.support.v4.media.MediaMetadataCompat#getString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaControllerService.java From Noyze with Apache License 2.0 | 8 votes |
@Produce public Pair<MediaMetadataCompat, PlaybackStateCompat> produceEvent() { final MediaMetadataCompat metadata; if (null == mController.getMetadata()) { metadata = (new MediaMetadataCompat.Builder()).build(); } else { // If the notification didn't provide an icon, add one! MediaMetadataCompat metadata1 = mController.getMetadata(); String packageName = metadata1.getString(RemoteControlCompat.METADATA_KEY_PACKAGE); if (!metadata1.containsKey(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON) && mLargeIconMap.containsKey(packageName)) { MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(metadata1); builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, mLargeIconMap.get(packageName)); metadata1 = builder.build(); } metadata = metadata1; } return Pair.create(metadata, mController.getPlaybackState()); }
Example 2
Source File: MusicService.java From LyricHere with Apache License 2.0 | 6 votes |
@Override public void onCustomAction(@NonNull String action, Bundle extras) { if (CUSTOM_ACTION_THUMBS_UP.equals(action)) { LogUtils.i(TAG, "onCustomAction: favorite for current track"); MediaMetadataCompat track = getCurrentPlayingMusic(); if (track != null) { String musicId = track.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicProvider.setFavorite(musicId, !mMusicProvider.isFavorite(musicId)); } // playback state needs to be updated because the "Favorite" icon on the // custom action will change to reflect the new favorite state. updatePlaybackState(null); } else { LogUtils.e(TAG, "Unsupported action: ", action); } }
Example 3
Source File: MusicProvider.java From LyricHere with Apache License 2.0 | 6 votes |
public synchronized void updateMusic(String musicId, MediaMetadataCompat metadata) { MutableMediaMetadata track = mMusicListById.get(musicId); if (track == null) { return; } String oldGenre = track.metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE); String newGenre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE); track.metadata = metadata; // if genre has changed, we need to rebuild the list by genre if (!oldGenre.equals(newGenre)) { buildListsByGenre(); } }
Example 4
Source File: MediaControllerService.java From Noyze with Apache License 2.0 | 6 votes |
@Produce public Pair<MediaMetadataCompat, PlaybackStateCompat> produceEvent() { final MediaMetadataCompat metadata; if (null == mController.getMetadata()) { metadata = (new MediaMetadataCompat.Builder()).build(); } else { // If the notification didn't provide an icon, add one! MediaMetadataCompat metadata1 = mController.getMetadata(); String packageName = metadata1.getString(RemoteControlCompat.METADATA_KEY_PACKAGE); if (!metadata1.containsKey(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON) && mLargeIconMap.containsKey(packageName)) { MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(metadata1); builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, mLargeIconMap.get(packageName)); metadata1 = builder.build(); } metadata = metadata1; } return Pair.create(metadata, mController.getPlaybackState()); }
Example 5
Source File: RemoteControlCompat.java From Noyze with Apache License 2.0 | 6 votes |
/** * @return The {@link android.graphics.Bitmap} references by {@link android.support.v4.media.MediaMetadataCompat} * @throws FileNotFoundException If an error parsing the {@link android.net.Uri} occurred. */ public static Bitmap getBitmap(Context context, MediaMetadataCompat metadata) throws FileNotFoundException{ if (null == metadata) return null; Bitmap albumArtBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART); // No album art... check the URI. if (null == albumArtBitmap) { String albumArtUri = metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI); // Still no URI... check the art URI. if (TextUtils.isEmpty(albumArtUri)) albumArtUri = metadata.getString(MediaMetadataCompat.METADATA_KEY_ART_URI); // If we've got a URI, try to load it. if (!TextUtils.isEmpty(albumArtUri)) { ContentResolver cr = context.getContentResolver(); albumArtBitmap = BitmapFactory.decodeStream(cr.openInputStream(Uri.parse(albumArtUri))); } } return albumArtBitmap; }
Example 6
Source File: RemoteControlCompat.java From Noyze with Apache License 2.0 | 6 votes |
/** * @return The {@link android.graphics.Bitmap} references by {@link android.support.v4.media.MediaMetadataCompat} * @throws FileNotFoundException If an error parsing the {@link android.net.Uri} occurred. */ public static Bitmap getBitmap(Context context, MediaMetadataCompat metadata) throws FileNotFoundException{ if (null == metadata) return null; Bitmap albumArtBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART); // No album art... check the URI. if (null == albumArtBitmap) { String albumArtUri = metadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI); // Still no URI... check the art URI. if (TextUtils.isEmpty(albumArtUri)) albumArtUri = metadata.getString(MediaMetadataCompat.METADATA_KEY_ART_URI); // If we've got a URI, try to load it. if (!TextUtils.isEmpty(albumArtUri)) { ContentResolver cr = context.getContentResolver(); albumArtBitmap = BitmapFactory.decodeStream(cr.openInputStream(Uri.parse(albumArtUri))); } } return albumArtBitmap; }
Example 7
Source File: TrackFragment.java From Melophile with Apache License 2.0 | 5 votes |
private void updateArt(MediaMetadataCompat metadataCompat) { if (metadataCompat == null) return; String text = Long.toString(metadataCompat.getLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER)) + " of " + Long.toString(metadataCompat.getLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS)); trackName.setText(metadataCompat.getText(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE)); artist.setText(metadataCompat.getText(MediaMetadataCompat.METADATA_KEY_ARTIST)); pages.setText(text); String imageUrl = metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI); showArt(imageUrl); }
Example 8
Source File: MusicService.java From LyricHere with Apache License 2.0 | 5 votes |
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; } LogUtils.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); } }
Example 9
Source File: MusicProvider.java From LyricHere with Apache License 2.0 | 5 votes |
private synchronized void retrieveMediaFromGoogle() { try { if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; int slashPos = CATALOG_URL.lastIndexOf('/'); String path = CATALOG_URL.substring(0, slashPos + 1); JSONObject jsonObj = fetchJSONFromUrl(CATALOG_URL); if (jsonObj == null) { return; } JSONArray tracks = jsonObj.getJSONArray(JSON_MUSIC); if (tracks != null) { for (int j = 0; j < tracks.length(); j++) { MediaMetadataCompat item = buildFromJSON(tracks.getJSONObject(j), path); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); } mCurrentState = State.INITIALIZED; } } catch (JSONException e) { LogUtils.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; } } }
Example 10
Source File: RemoteControlCompat.java From Noyze with Apache License 2.0 | 5 votes |
/** @see {@link #getBitmap(android.content.Context, android.support.v4.media.MediaMetadataCompat)} */ public static Bitmap getIcon(Context context, MediaMetadataCompat metadata) throws FileNotFoundException{ if (null == metadata) return null; Bitmap albumArtBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON); // No icon... check the URI. if (null == albumArtBitmap) { String albumArtUri = metadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI); // If we've got a URI, try to load it. if (!TextUtils.isEmpty(albumArtUri)) { ContentResolver cr = context.getContentResolver(); albumArtBitmap = BitmapFactory.decodeStream(cr.openInputStream(Uri.parse(albumArtUri))); } } return albumArtBitmap; }
Example 11
Source File: RemoteControlCompat.java From Noyze with Apache License 2.0 | 5 votes |
/** @see {@link #getBitmap(android.content.Context, android.support.v4.media.MediaMetadataCompat)} */ public static Bitmap getIcon(Context context, MediaMetadataCompat metadata) throws FileNotFoundException{ if (null == metadata) return null; Bitmap albumArtBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON); // No icon... check the URI. if (null == albumArtBitmap) { String albumArtUri = metadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI); // If we've got a URI, try to load it. if (!TextUtils.isEmpty(albumArtUri)) { ContentResolver cr = context.getContentResolver(); albumArtBitmap = BitmapFactory.decodeStream(cr.openInputStream(Uri.parse(albumArtUri))); } } return albumArtBitmap; }
Example 12
Source File: LocalPlayback.java From LyricHere with Apache License 2.0 | 4 votes |
@Override public void play(QueueItem item) { mPlayOnFocusGain = true; 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 && mMediaPlayer != null) { configMediaPlayerState(); } else { mState = PlaybackStateCompat.STATE_STOPPED; relaxResources(false); // release everything except MediaPlayer MediaMetadataCompat track = mMusicProvider.getMusic( MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId())); String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE); try { createMediaPlayerIfNeeded(); mState = PlaybackStateCompat.STATE_BUFFERING; mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setDataSource(source); // 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! mMediaPlayer.prepareAsync(); // 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(); if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } } catch (IOException ex) { LogUtils.e(TAG, ex, "Exception playing song"); if (mCallback != null) { mCallback.onError(ex.getMessage()); } } } }