@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if (!LibVlcUtil.isICSOrLater()) // NOP check return; Media media = getCurrentMedia(); if (mRemoteControlClient != null && media != null) { MetadataEditor editor = mRemoteControlClient.editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength()); // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap. Bitmap cover = getCover(); editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, ((cover != null) ? cover.copy(cover.getConfig(), false) : null)); editor.apply(); } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if(!Util.isICSOrLater()) // NOP check return; Media media = getCurrentMedia(); if (mRemoteControlClient != null && media != null) { MetadataEditor editor = mRemoteControlClient.editMetadata(true); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength()); editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, getCover()); editor.apply(); } }
public void showNotify(String artist, String album, String title, int tracknr) { getAudioFocus(); mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); MetadataEditor edit = mRemoteControlClient.editMetadata(true); edit.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title); edit.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist); edit.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, artist); edit.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album); edit.putLong(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, tracknr); edit.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, 10); edit.apply(); int timeout = getTimeout(); if (timeout != 0) { mHandler.removeMessages(HANDLER_WHAT_CLEAR); mHandler.sendEmptyMessageDelayed(HANDLER_WHAT_CLEAR, timeout * 1000); } }
public static void setMetadata(Object rccObj, Bundle metadata, long actions) { MetadataEditor editor = ((RemoteControlClient) rccObj).editMetadata(true); MediaSessionCompatApi14.buildOldMetadata(metadata, editor); addNewMetadata(metadata, editor); if ((128 & actions) != 0) { editor.addEditableKey(268435457); } editor.apply(); }
static void addNewMetadata(Bundle metadata, MetadataEditor editor) { if (metadata != null) { if (metadata.containsKey("android.media.metadata.YEAR")) { editor.putLong(8, metadata.getLong("android.media.metadata.YEAR")); } if (metadata.containsKey("android.media.metadata.RATING")) { editor.putObject(101, metadata.getParcelable("android.media.metadata.RATING")); } if (metadata.containsKey("android.media.metadata.USER_RATING")) { editor.putObject(268435457, metadata.getParcelable("android.media.metadata.USER_RATING")); } } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void updateRemoteControlClientMetadata() { if (!AndroidUtil.isICSOrLater()) // NOP check return; MediaWrapper media = getCurrentMedia(); if (mRemoteControlClient != null && media != null) { MetadataEditor editor = mRemoteControlClient.editMetadata(true); if (media.getNowPlaying() != null) { editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, ""); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, ""); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getNowPlaying()); } else { editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, ""); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, Util.getMediaAlbum(this, media)); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, Util.getMediaArtist(this, media)); } editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, Util.getMediaGenre(this, media)); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength()); // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap. Bitmap cover = AudioUtil.getCover(this, media, 512); if (cover != null && cover.getConfig() != null) //In case of format not supported editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, (cover.copy(cover.getConfig(), false))); editor.apply(); } //Send metadata to Pebble watch if (media != null && mPebbleEnabled) { final Intent i = new Intent("com.getpebble.action.NOW_PLAYING"); i.putExtra("artist", Util.getMediaArtist(this, media)); i.putExtra("album", Util.getMediaAlbum(this, media)); i.putExtra("track", media.getTitle()); sendBroadcast(i); } }
/** * Notify the change-receivers that something has changed. * The intent that is sent contains the following data * for the currently playing track: * "id" - Integer: the database row ID * "artist" - String: the name of the artist * "album" - String: the name of the album * "track" - String: the name of the track * The intent has an action that is one of * "com.android.music.metachanged" * "com.android.music.queuechanged", * "com.android.music.playbackcomplete" * "com.android.music.playstatechanged" * respectively indicating that a new track has * started playing, that the playback queue has * changed, that playback has stopped because * the last file in the list has been played, * or that the play-state changed (paused/resumed). */ private void notifyChange(String what) { Intent i = new Intent(what); i.putExtra("id", Long.valueOf(getAudioId())); i.putExtra("artist", getArtistName()); i.putExtra("album",getAlbumName()); i.putExtra("track", getTrackName()); i.putExtra("playing", isPlaying()); sendStickyBroadcast(i); if (what.equals(PLAYSTATE_CHANGED)) { mRemoteControlClient.setPlaybackState(isPlaying() ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED); } else if (what.equals(META_CHANGED)) { RemoteControlClient.MetadataEditor ed = mRemoteControlClient.editMetadata(true); ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName()); ed.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration()); Bitmap b = MusicUtils.getArtwork(this, getAudioId(), getAlbumId(), false); if (b != null) { ed.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, b); } ed.apply(); } if (what.equals(QUEUE_CHANGED)) { saveQueue(true); } else { saveQueue(false); } // Share this notification directly with our widgets mAppWidgetProvider.notifyChange(this, what); }
@TargetApi(14) private void setMusicCover(Bitmap cover) { if (Build.VERSION.SDK_INT > 14 && remoteControlClient != null) { ((RemoteControlClient) remoteControlClient).editMetadata(false) .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, cover).apply(); } }
@TargetApi(14) private void setMusicInfo(Music song) { if (Build.VERSION.SDK_INT > 14 && remoteControlClient != null && song != null) { MetadataEditor editor = ((RemoteControlClient) remoteControlClient).editMetadata(true); //TODO : maybe add cover art here someday editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, song.getTime() * 1000); editor.putLong(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, song.getTrack()); editor.putLong(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, song.getDisc()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, song.getAlbum()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, song.getAlbumArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, song.getArtist()); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, song.getTitle()); editor.apply(); } }
public static void setMetadata(Object rccObj, Bundle metadata) { MetadataEditor editor = ((RemoteControlClient) rccObj).editMetadata(true); buildOldMetadata(metadata, editor); editor.apply(); }
static void buildOldMetadata(Bundle metadata, MetadataEditor editor) { if (metadata != null) { if (metadata.containsKey("android.media.metadata.ART")) { editor.putBitmap(100, (Bitmap) metadata.getParcelable("android.media.metadata.ART")); } else if (metadata.containsKey("android.media.metadata.ALBUM_ART")) { editor.putBitmap(100, (Bitmap) metadata.getParcelable("android.media.metadata.ALBUM_ART")); } if (metadata.containsKey("android.media.metadata.ALBUM")) { editor.putString(1, metadata.getString("android.media.metadata.ALBUM")); } if (metadata.containsKey("android.media.metadata.ALBUM_ARTIST")) { editor.putString(13, metadata.getString("android.media.metadata.ALBUM_ARTIST")); } if (metadata.containsKey("android.media.metadata.ARTIST")) { editor.putString(2, metadata.getString("android.media.metadata.ARTIST")); } if (metadata.containsKey("android.media.metadata.AUTHOR")) { editor.putString(3, metadata.getString("android.media.metadata.AUTHOR")); } if (metadata.containsKey("android.media.metadata.COMPILATION")) { editor.putString(15, metadata.getString("android.media.metadata.COMPILATION")); } if (metadata.containsKey("android.media.metadata.COMPOSER")) { editor.putString(4, metadata.getString("android.media.metadata.COMPOSER")); } if (metadata.containsKey("android.media.metadata.DATE")) { editor.putString(5, metadata.getString("android.media.metadata.DATE")); } if (metadata.containsKey("android.media.metadata.DISC_NUMBER")) { editor.putLong(14, metadata.getLong("android.media.metadata.DISC_NUMBER")); } if (metadata.containsKey("android.media.metadata.DURATION")) { editor.putLong(9, metadata.getLong("android.media.metadata.DURATION")); } if (metadata.containsKey("android.media.metadata.GENRE")) { editor.putString(6, metadata.getString("android.media.metadata.GENRE")); } if (metadata.containsKey("android.media.metadata.TITLE")) { editor.putString(7, metadata.getString("android.media.metadata.TITLE")); } if (metadata.containsKey("android.media.metadata.TRACK_NUMBER")) { editor.putLong(0, metadata.getLong("android.media.metadata.TRACK_NUMBER")); } if (metadata.containsKey("android.media.metadata.WRITER")) { editor.putString(11, metadata.getString("android.media.metadata.WRITER")); } } }
/** * Notify the change-receivers that something has changed. The intent that * is sent contains the following data for the currently playing track: "id" * - Integer: the database row ID "artist" - String: the name of the artist * "album" - String: the name of the album "track" - String: the name of the * track The intent has an action that is one of * "com.andrew.apolloMod.metachanged" "com.andrew.apolloMod.queuechanged", * "com.andrew.apolloMod.playbackcomplete" "com.andrew.apolloMod.playstatechanged" * respectively indicating that a new track has started playing, that the * playback queue has changed, that playback has stopped because the last * file in the list has been played, or that the play-state changed * (paused/resumed). */ public void notifyChange(String what) { Intent i = new Intent(what); i.putExtra("id", Long.valueOf(getAudioId())); i.putExtra("artist", getArtistName()); i.putExtra("album", getAlbumName()); i.putExtra("track", getTrackName()); i.putExtra("playing", mIsSupposedToBePlaying); i.putExtra("isfavorite", isFavorite()); sendStickyBroadcast(i); i = new Intent(i); i.setAction(what.replace(APOLLO_PACKAGE_NAME, MUSIC_PACKAGE_NAME)); sendStickyBroadcast(i); if (what.equals(PLAYSTATE_CHANGED)) { mRemoteControlClient .setPlaybackState(mIsSupposedToBePlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED); } else if (what.equals(META_CHANGED)) { MetadataEditor ed = mRemoteControlClient.editMetadata(true); ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName()); ed.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration()); Bitmap b = getAlbumBitmap(); if (b != null) { ed.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, b); } ed.apply(); } if (what.equals(QUEUE_CHANGED)) { saveQueue(true); } else { saveQueue(false); } mAppWidgetProvider1x1.notifyChange(this, what); mAppWidgetProvider4x1.notifyChange(this, what); mAppWidgetProvider4x2.notifyChange(this, what); }
/** * Refresh player status and metadata. */ @SuppressLint("NewApi") private void refreshRemoteControlClientState(PlaybackServiceMediaPlayer.PSMPInfo info) { if (android.os.Build.VERSION.SDK_INT >= 14) { if (remoteControlClient != null) { switch (info.playerStatus) { case PLAYING: remoteControlClient .setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); break; case PAUSED: case INITIALIZED: remoteControlClient .setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); break; case STOPPED: remoteControlClient .setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED); break; case ERROR: remoteControlClient .setPlaybackState(RemoteControlClient.PLAYSTATE_ERROR); break; default: remoteControlClient .setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING); } if (info.playable != null) { MetadataEditor editor = remoteControlClient .editMetadata(false); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, info.playable.getEpisodeTitle()); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, info.playable.getFeedTitle()); editor.apply(); } if (AppConfig.DEBUG) Log.d(TAG, "RemoteControlClient state was refreshed"); } } }
/** * Notify the change-receivers that something has changed. The intent that * is sent contains the following data for the currently playing track: "id" * - Integer: the database row ID "artist" - String: the name of the artist * "album" - String: the name of the album "track" - String: the name of the * track The intent has an action that is one of * "com.cp.monsterMod.metachanged" "com.cp.monsterMod.queuechanged", * "com.cp.monsterMod.playbackcomplete" "com.cp.monsterMod.playstatechanged" * respectively indicating that a new track has started playing, that the * playback queue has changed, that playback has stopped because the last * file in the list has been played, or that the play-state changed * (paused/resumed). */ public void notifyChange(String what) { Intent i = new Intent(what); i.putExtra("id", Long.valueOf(getAudioId())); i.putExtra("artist", getArtistName()); i.putExtra("album", getAlbumName()); i.putExtra("track", getTrackName()); i.putExtra("playing", mIsSupposedToBePlaying); i.putExtra("isfavorite", isFavorite()); //粘滞广播 sendStickyBroadcast(i); i = new Intent(i); i.setAction(what.replace(APOLLO_PACKAGE_NAME, MUSIC_PACKAGE_NAME)); sendStickyBroadcast(i); if (what.equals(PLAYSTATE_CHANGED)) { mRemoteControlClient .setPlaybackState(mIsSupposedToBePlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED); } else if (what.equals(META_CHANGED)) { RemoteControlClient.MetadataEditor ed = mRemoteControlClient.editMetadata(true); ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName()); ed.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration()); Bitmap b = getAlbumBitmap(); if (b != null) { ed.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, b); } ed.apply(); } if (what.equals(QUEUE_CHANGED)) { saveQueue(true); } else { saveQueue(false); } mAppWidgetProvider1x1.notifyChange(this, what); mAppWidgetProvider4x1.notifyChange(this, what); mAppWidgetProvider4x2.notifyChange(this, what); }
/** * Notify the change-receivers that something has changed. The intent that * is sent contains the following data for the currently playing track: "id" * - Integer: the database row ID "artist" - String: the name of the artist * "album" - String: the name of the album "track" - String: the name of the * track The intent has an action that is one of * "com.andrew.apolloMod.metachanged" "com.andrew.apolloMod.queuechanged", * "com.andrew.apolloMod.playbackcomplete" "com.andrew.apolloMod.playstatechanged" * respectively indicating that a new track has started playing, that the * playback queue has changed, that playback has stopped because the last * file in the list has been played, or that the play-state changed * (paused/resumed). */ public void notifyChange(String what) { Intent i = new Intent(what); i.putExtra("id", Long.valueOf(getAudioId())); i.putExtra("artist", getArtistName()); i.putExtra("album", getAlbumName()); i.putExtra("track", getTrackName()); i.putExtra("playing", mIsSupposedToBePlaying); i.putExtra("isfavorite", isFavorite()); sendStickyBroadcast(i); i = new Intent(i); i.setAction(what.replace(APOLLO_PACKAGE_NAME, MUSIC_PACKAGE_NAME)); sendStickyBroadcast(i); if (what.equals(PLAYSTATE_CHANGED)) { mRemoteControlClient .setPlaybackState(mIsSupposedToBePlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED); } else if (what.equals(META_CHANGED)) { RemoteControlClient.MetadataEditor ed = mRemoteControlClient.editMetadata(true); ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName()); ed.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration()); Bitmap b = getAlbumBitmap(); if (b != null) { ed.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, b); } ed.apply(); } if (what.equals(QUEUE_CHANGED)) { saveQueue(true); } else { saveQueue(false); } mAppWidgetProvider1x1.notifyChange(this, what); mAppWidgetProvider4x1.notifyChange(this, what); mAppWidgetProvider4x2.notifyChange(this, what); }
/** * Notify the change-receivers that something has changed. The intent that * is sent contains the following data for the currently playing track: "id" * - Integer: the database row ID "artist" - String: the name of the artist * "album" - String: the name of the album "track" - String: the name of the * track The intent has an action that is one of * "com.aniruddhc.xPlod.metachanged" "com.aniruddhc.xPlod.queuechanged", * "com.aniruddhc.xPlod.playbackcomplete" "com.aniruddhc.xPlod.playstatechanged" * respectively indicating that a new track has started playing, that the * playback queue has changed, that playback has stopped because the last * file in the list has been played, or that the play-state changed * (paused/resumed). */ public void notifyChange(String what) { Intent i = new Intent(what); i.putExtra("id", Long.valueOf(getAudioId())); i.putExtra("artist", getArtistName()); i.putExtra("album", getAlbumName()); i.putExtra("track", getTrackName()); i.putExtra("playing", mIsSupposedToBePlaying); i.putExtra("isfavorite", isFavorite()); sendStickyBroadcast(i); i = new Intent(i); i.setAction(what.replace(APOLLO_PACKAGE_NAME, MUSIC_PACKAGE_NAME)); sendStickyBroadcast(i); if (what.equals(PLAYSTATE_CHANGED)) { mRemoteControlClient .setPlaybackState(mIsSupposedToBePlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED); } else if (what.equals(META_CHANGED)) { RemoteControlClient.MetadataEditor ed = mRemoteControlClient.editMetadata(true); ed.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, getTrackName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, getAlbumName()); ed.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, getArtistName()); ed.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration()); Bitmap b = getAlbumBitmap(); if (b != null) { ed.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, b); } ed.apply(); } if (what.equals(QUEUE_CHANGED)) { saveQueue(true); } else { saveQueue(false); } mAppWidgetProvider1x1.notifyChange(this, what); mAppWidgetProvider4x1.notifyChange(this, what); mAppWidgetProvider4x2.notifyChange(this, what); }