List of usage examples for android.media MediaMetadataRetriever METADATA_KEY_ALBUM
int METADATA_KEY_ALBUM
To view the source code for android.media MediaMetadataRetriever METADATA_KEY_ALBUM.
Click Source Link
From source file:org.gateshipone.odyssey.utils.FileExplorerHelper.java
/** * create a TrackModel for the given File * if no entry in the mediadb is found a dummy TrackModel will be created */// w w w. j a v a2 s .c o m public TrackModel getTrackModelForFile(Context context, FileModel file) { TrackModel track = null; String urlString = file.getURLString(); if (mTrackHash.isEmpty()) { // lookup the current file in the media db String whereVal[] = { urlString }; String where = MediaStore.Audio.Media.DATA + "=?"; Cursor cursor = PermissionHelper.query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MusicLibraryHelper.projectionTracks, where, whereVal, MediaStore.Audio.Media.TRACK); if (cursor != null) { if (cursor.moveToFirst()) { String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION)); int no = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.TRACK)); String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)); String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM)); String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA)); String albumKey = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_KEY)); long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); track = new TrackModel(title, artist, album, albumKey, duration, no, url, id); } cursor.close(); } } else { // use pre built hash to lookup the file track = mTrackHash.get(urlString); } if (track == null) { // no entry in the media db was found so create a custom track try { // try to read the file metadata MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(context, Uri.parse(FormatHelper.encodeFileURI(urlString))); String title = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); if (title == null) { title = file.getName(); } String durationString = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); long duration = 0; if (durationString != null) { try { duration = Long.valueOf(durationString); } catch (NumberFormatException e) { duration = 0; } } String noString = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER); int no = -1; if (noString != null) { try { if (noString.contains("/")) { // if string has the format (trackNumber / numberOfTracks) String[] components = noString.split("/"); if (components.length > 0) { no = Integer.valueOf(components[0]); } } else { no = Integer.valueOf(noString); } } catch (NumberFormatException e) { no = -1; } } String artist = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); String album = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM); String albumKey = "" + ((artist == null ? "" : artist) + (album == null ? "" : album)).hashCode(); track = new TrackModel(title, artist, album, albumKey, duration, no, urlString, -1); } catch (Exception e) { String albumKey = "" + file.getName().hashCode(); track = new TrackModel(file.getName(), "", "", albumKey, 0, -1, urlString, -1); } } return track; }
From source file:org.amahi.anywhere.service.AudioService.java
private void setUpAudioPlayerRemote(AudioMetadataFormatter audioMetadataFormatter, Bitmap audioAlbumArt) { audioPlayerRemote.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, audioMetadataFormatter.getAudioTitle(audioFile)) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, audioMetadataFormatter.getAudioSubtitle(audioShare)) .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, getAudioPlayerRemoteArtwork(audioAlbumArt)) .apply();/* ww w. j a va2 s. c o m*/ }
From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java
/** * Updates {@link #mMetadata metadata} from given remote metadata class. * This also updates play state.//from ww w. j ava 2 s. c o m * * @param data Object of metadata to update from, or {@code null} to clear local metadata. * @see #clearMetadata() */ private void updateMetadata(@Nullable RemoteController.MetadataEditor data) { if (data == null) { if (mMetadata.isEmpty()) return; mMetadata.clear(); } else { mMetadata.title = data.getString(MediaMetadataRetriever.METADATA_KEY_TITLE, null); mMetadata.artist = data.getString(MediaMetadataRetriever.METADATA_KEY_ARTIST, null); mMetadata.album = data.getString(MediaMetadataRetriever.METADATA_KEY_ALBUM, null); mMetadata.duration = data.getLong(MediaMetadataRetriever.METADATA_KEY_DURATION, -1); mMetadata.bitmap = data.getBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK, null); mMetadata.generateSubtitle(); } notifyOnMetadataChanged(); }
From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java
/** * Update the RemoteControlClient//from w w w. j a v a 2 s. c om */ private void updateRemoteControlClient() { // Update playstate if (App.mClementine.getState() == Clementine.State.PLAY) { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } // Get the metadata editor if (mLastSong != null && mLastSong.getArt() != null) { RemoteControlClient.MetadataEditor editor = mRcClient.editMetadata(false); editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, mLastSong.getArt()); // The RemoteControlClients displays the following info: // METADATA_KEY_TITLE (white) - METADATA_KEY_ALBUMARTIST (grey) - METADATA_KEY_ALBUM (grey) // // So i put the metadata not in the "correct" fields to display artist, track and album // TODO: Fix it when changed in newer android versions editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, mLastSong.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, mLastSong.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, mLastSong.getTitle()); editor.apply(); } }
From source file:com.andreadec.musicplayer.MusicService.java
private void updateNotificationMessage() { /* Update remote control client */ if (Build.VERSION.SDK_INT >= 14) { if (currentPlayingItem == null) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); } else {//from ww w . ja v a2s.c o m if (isPlaying()) { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, currentPlayingItem.getTitle()); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, currentPlayingItem.getArtist()); metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, currentPlayingItem.getArtist()); metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, getDuration()); if (currentPlayingItem.hasImage()) { metadataEditor.putBitmap(METADATA_KEY_ARTWORK, currentPlayingItem.getImage()); } else { metadataEditor.putBitmap(METADATA_KEY_ARTWORK, icon.copy(icon.getConfig(), false)); } metadataEditor.apply(); } } /* Update notification */ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.audio_white); //notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); notificationBuilder.setOngoing(true); int playPauseIcon = isPlaying() ? R.drawable.pause : R.drawable.play; //int playPauseString = isPlaying() ? R.string.pause : R.string.play; notificationBuilder.setContentIntent(pendingIntent); String notificationMessage = ""; if (currentPlayingItem == null) { notificationMessage = getResources().getString(R.string.noSong); } else { if (currentPlayingItem.getArtist() != null && !currentPlayingItem.getArtist().equals("")) notificationMessage = currentPlayingItem.getArtist() + " - "; notificationMessage += currentPlayingItem.getTitle(); } /*notificationBuilder.addAction(R.drawable.previous, getResources().getString(R.string.previous), previousPendingIntent); notificationBuilder.addAction(playPauseIcon, getResources().getString(playPauseString), playpausePendingIntent); notificationBuilder.addAction(R.drawable.next, getResources().getString(R.string.next), nextPendingIntent);*/ notificationBuilder.setContentTitle(getResources().getString(R.string.app_name)); notificationBuilder.setContentText(notificationMessage); notification = notificationBuilder.build(); RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.layout_notification); if (currentPlayingItem == null) { notificationLayout.setTextViewText(R.id.textViewArtist, getString(R.string.app_name)); notificationLayout.setTextViewText(R.id.textViewTitle, getString(R.string.noSong)); notificationLayout.setImageViewBitmap(R.id.imageViewNotification, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } else { notificationLayout.setTextViewText(R.id.textViewArtist, currentPlayingItem.getArtist()); notificationLayout.setTextViewText(R.id.textViewTitle, currentPlayingItem.getTitle()); Bitmap image = currentPlayingItem.getImage(); if (image != null) { notificationLayout.setImageViewBitmap(R.id.imageViewNotification, image); } else { notificationLayout.setImageViewBitmap(R.id.imageViewNotification, BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } } notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationQuit, quitPendingIntent); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPrevious, previousPendingIntent); notificationLayout.setImageViewResource(R.id.buttonNotificationPlayPause, playPauseIcon); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationPlayPause, playpausePendingIntent); notificationLayout.setOnClickPendingIntent(R.id.buttonNotificationNext, nextPendingIntent); notification.bigContentView = notificationLayout; notificationManager.notify(Constants.NOTIFICATION_MAIN, notification); }
From source file:com.twistedequations.rotor.MediaMetadataCompat.java
@TargetApi(Build.VERSION_CODES.KITKAT) private static void fillEditorKeyMapping() { EDITOR_KEY_MAPPING = new SparseArray<String>(); EDITOR_KEY_MAPPING.put(MediaMetadataEditor.BITMAP_KEY_ARTWORK, METADATA_KEY_ART); EDITOR_KEY_MAPPING.put(MediaMetadataEditor.RATING_KEY_BY_OTHERS, METADATA_KEY_RATING); EDITOR_KEY_MAPPING.put(MediaMetadataEditor.RATING_KEY_BY_USER, METADATA_KEY_USER_RATING); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ALBUM, METADATA_KEY_ALBUM); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, METADATA_KEY_ALBUM_ARTIST); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ARTIST, METADATA_KEY_ARTIST); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_AUTHOR, METADATA_KEY_AUTHOR); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, METADATA_KEY_TRACK_NUMBER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_COMPOSER, METADATA_KEY_COMPOSER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_COMPILATION, METADATA_KEY_COMPILATION); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DATE, METADATA_KEY_DATE); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, METADATA_KEY_DISC_NUMBER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DURATION, METADATA_KEY_DURATION); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_GENRE, METADATA_KEY_GENRE); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS, METADATA_KEY_NUM_TRACKS); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_TITLE, METADATA_KEY_TITLE); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_WRITER, METADATA_KEY_WRITER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_YEAR, METADATA_KEY_YEAR); }
From source file:com.twistedequations.rotor.MediaMetadataCompat.java
@TargetApi(Build.VERSION_CODES.KITKAT) private static void fillEditorTypeMapping() { EDITOR_KEYS_TYPE = new SparseArray<Integer>(26); EDITOR_KEYS_TYPE.put(MediaMetadataEditor.BITMAP_KEY_ARTWORK, METADATA_TYPE_BITMAP); EDITOR_KEYS_TYPE.put(MediaMetadataEditor.RATING_KEY_BY_OTHERS, METADATA_TYPE_RATING); EDITOR_KEYS_TYPE.put(MediaMetadataEditor.RATING_KEY_BY_USER, METADATA_TYPE_RATING); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_ALBUM, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_ARTIST, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_AUTHOR, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, METADATA_TYPE_LONG); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_COMPOSER, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_COMPILATION, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_DATE, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, METADATA_TYPE_LONG); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_DURATION, METADATA_TYPE_LONG); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_YEAR, METADATA_TYPE_LONG); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_GENRE, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_TITLE, METADATA_TYPE_TEXT); EDITOR_KEYS_TYPE.put(MediaMetadataRetriever.METADATA_KEY_WRITER, METADATA_TYPE_TEXT); }
From source file:co.shunya.gita.player.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next.// w w w . j a va 2 s . com */ void playNextSong(Long id) { if (id == null || id < 0) { throw new IllegalArgumentException("id must be non nul +ve"); } setState(State.Stopped); relaxResources(false); // release everything except MediaPlayer try { // set the source of the media player to a manual URL or path Track playingItem = mRetriever.getItem(id); createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); if (playingItem == null) { Toast.makeText(this, "All Tracks of current category is been played", Toast.LENGTH_LONG).show(); processStopRequest(true); // stop everything! return; } // BusProvider.getInstance().post(playingItem); mCurrentID = id; mPlayer.setDataSource(playingItem.isDownloded() ? playingItem.getLocalUrl(this) : playingItem.getUrl()); mIsStreaming = playingItem.getUrl().startsWith("http:") || playingItem.getUrl().startsWith("https:"); mSongTitle = playingItem.getTitle(); setState(State.Preparing); updateUI(); setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "Gita") .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, playingItem.getTitle()) .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // 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! mPlayer.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. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) mWifiLock.acquire(); else if (mWifiLock.isHeld()) mWifiLock.release(); } catch (IOException ex) { Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); ex.printStackTrace(); } }
From source file:com.geryon.ocraa.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next.//from ww w .java 2 s.c om */ void playNextSong(int pos) { position = pos; mState = State.Stopped; progressBarHandler.removeCallbacks(mUpdateTimeTask); MusicRetriever.Item playingItem = null; relaxResources(false); // release everything except MediaPlayer try { if ((position == -1) || (repeat == false && shuffle == true)) { Random mRandom = new Random(); int random = mRandom.nextInt(mRetriever.ItemSize()); playingItem = mRetriever.getItem(random); Log.d("Randomize:", String.valueOf(random)); position = random; Log.d("Position:", String.valueOf(random)); if (playingItem == null) { Toast.makeText(this, "No available music to play. Place some music on your external storage " + "device (e.g. your SD card) and try again.", Toast.LENGTH_LONG).show(); processStopRequest(true); // stop everything! return; } createMediaPlayerIfNeeded(); mPlayer.setDataSource(playingItem.getURI().toString()); } else if (position != -1) { if (repeat == false) { if (shuffle == false) { if (position == mRetriever.ItemSize() - 1) { position = 0; } else { position++; } } } playingItem = mRetriever.getItem(position); createMediaPlayerIfNeeded(); mPlayer.setDataSource(playingItem.getURI().toString()); } mSongTitle = playingItem.getTitle(); mState = State.Preparing; setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, playingItem.getArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, playingItem.getAlbum()) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, playingItem.getTitle()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, playingItem.getDuration()) // TODO: fetch real item artwork .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // 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! mPlayer.prepareAsync(); updateProgressBar(); // 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. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) mWifiLock.acquire(); else if (mWifiLock.isHeld()) mWifiLock.release(); } catch (IOException ex) { // Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); // ex.printStackTrace(); } }
From source file:com.namelessdev.mpdroid.NotificationService.java
/** * Update the remote controls.//w w w . jav a 2s. co m * * @param mpdStatus The current server status object. */ private void updateRemoteControlClient(final MPDStatus mpdStatus) { final int state = getRemoteState(mpdStatus); mRemoteControlClient.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, mCurrentMusic.getAlbum()) .putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, mCurrentMusic.getAlbumArtist()) .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, mCurrentMusic.getArtist()) .putLong(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, (long) mCurrentMusic.getTrack()) .putLong(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, (long) mCurrentMusic.getDisc()) .putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, mCurrentMusic.getTime() * DateUtils.SECOND_IN_MILLIS) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, mCurrentMusic.getTitle()) .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, mAlbumCover).apply(); /** Notify of the elapsed time if on 4.3 or higher */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { mRemoteControlClient.setPlaybackState(state, lastKnownElapsed, 1.0f); } else { mRemoteControlClient.setPlaybackState(state); } Log.d(TAG, "Updated remote client with state " + state + " for music " + mCurrentMusic); }