@Override public void onClientMetadataUpdate(RemoteController.MetadataEditor data) { mMetadata.trackTitle = data.getString(MediaMetadataRetriever.METADATA_KEY_TITLE, mMetadata.trackTitle); mMetadata.bitmap = data.getBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK, mMetadata.bitmap); mClientIdLost = false; if ((mMetadata.trackTitle != null && !mMetadata.trackTitle.equals(mCurrentTrack)) || (mMetadata.bitmap != null && !mMetadata.bitmap.sameAs(mCurrentBitmap))) { mCurrentTrack = mMetadata.trackTitle; mCurrentBitmap = mMetadata.bitmap; refreshState(); if (DEBUG) log(getKey() + ": onClientMetadataUpdate"); } }
/** * Updates {@link #mMetadata metadata} from given remote metadata class. * This also updates play state. * * @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(); }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClient(final String what) { //Legacy for ICS if (mRemoteControlClient != null) { int playState = mIsSupposedToBePlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED; if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { Bitmap albumArt = null; if (mShowAlbumArtOnLockscreen) { albumArt = ImageLoader.getInstance().loadImageSync(TimberUtils.getAlbumArtUri(getAlbumId()).toString()); if (albumArt != null) { Bitmap.Config config = albumArt.getConfig(); if (config == null) { config = Bitmap.Config.ARGB_8888; } albumArt = albumArt.copy(config, false); } } RemoteControlClient.MetadataEditor editor = mRemoteControlClient.editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration()); editor.putBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK, albumArt); editor.apply(); } mRemoteControlClient.setPlaybackState(playState); } }
private synchronized Void updateClientBitmap(Bitmap bitmap) { if (remoteClientBitmap == bitmap) return null; final RemoteControlClient.MetadataEditor metaData = remoteControlClient.editMetadata(false); metaData.putBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK, bitmap).apply(); // Track the remote client bitmap and recycle it in case the remote control client // does not properly recycle the bitmap if (remoteClientBitmap != null) remoteClientBitmap.recycle(); remoteClientBitmap = bitmap; return null; }
@Override public void onClientMetadataUpdate(RemoteController.MetadataEditor metadataEditor) { // isRemoteControllerPlaying = true; durationObject = metadataEditor.getObject(MediaMetadataRetriever.METADATA_KEY_DURATION, 1200); //allow it to pass if not present artist = metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_ARTIST, metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, "")); track = metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_TITLE, ""); Bitmap artwork = metadataEditor.getBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK, null); mediaControllerCallback.saveArtwork(this, artwork, artist, track); }
@TargetApi(Build.VERSION_CODES.KITKAT) public static int BITMAP_KEY_ARTWORK() { return ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) ? MediaMetadataEditor.BITMAP_KEY_ARTWORK : _BITMAP_KEY_ARTWORK); }
public Metadata(MediaMetadataEditor editor) { bundle = new Bundle(); bundle.putBoolean(TAG, true); // Leave our mark! initFromMetadata(editor); }
/** * @return A {@link android.support.v4.media.MediaMetadataCompat} built from * a {@link android.media.MediaMetadataEditor} meant to bridge the two APIs. */ public static MediaMetadataCompat buildMediaMetadata(MediaMetadataEditor editor) { return mediaMetadata(editor).build(); }