下面列出了怎么用android.media.RemoteControlClient.MetadataEditor的API类实例代码及写法,或者点击链接到github查看源代码。
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);
}
}
/**
* 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");
}
}
}