本文整理匯總了Java中android.support.v4.media.MediaMetadataCompat類的典型用法代碼示例。如果您正苦於以下問題:Java MediaMetadataCompat類的具體用法?Java MediaMetadataCompat怎麽用?Java MediaMetadataCompat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MediaMetadataCompat類屬於android.support.v4.media包,在下文中一共展示了MediaMetadataCompat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createNotification
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
private Notification createNotification(){
if(mediaMetadata==null||playbackState==null) return null;
NotificationCompat.Builder builder=new NotificationCompat.Builder(service);
builder.setStyle(new NotificationCompat.MediaStyle()
.setMediaSession(token)
.setShowActionsInCompactView(1))
.setColor(Color.WHITE)
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setUsesChronometer(true)
.setDeleteIntent(dismissedNotification(service))
.setSmallIcon(R.drawable.ic_music_note)
.setContentIntent(contentIntent(service))
.setContentTitle(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST))
.setContentText(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE))
.addAction(prev(service));
if(playbackState.getState()==PlaybackStateCompat.STATE_PLAYING){
builder.addAction(pause(service));
}else{
builder.addAction(play(service));
}
builder.addAction(next(service));
setNotificationPlaybackState(builder);
loadImage(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI),builder);
return builder.build();
}
示例2: initializeMediaSession
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
private void initializeMediaSession() {
mSession = new MediaSessionCompat(this, TAG);
mSession.setFlags(
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mSession.setActive(true);
MediaControllerCompat.setMediaController(this, mSession.getController());
MediaMetadataCompat metadata = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mMovieView.getTitle())
.build();
mSession.setMetadata(metadata);
MediaSessionCallback mMediaSessionCallback = new MediaSessionCallback(mMovieView);
mSession.setCallback(mMediaSessionCallback);
int state =
mMovieView.isPlaying()
? PlaybackStateCompat.STATE_PLAYING
: PlaybackStateCompat.STATE_PAUSED;
updatePlaybackState(
state,
MEDIA_ACTIONS_ALL,
mMovieView.getCurrentPosition(),
mMovieView.getVideoResourceId());
}
示例3: updateRemoteControlClient
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
/**
* Updates the lockscreen controls.
*
* @param what The broadcast
*/
private void updateRemoteControlClient(final String what) {
int playState = isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
PlaybackStateCompat pmc = new PlaybackStateCompat.Builder()
.setState(playState, position(), 1.0f)
.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)
.build();
switch (what) {
case PLAYSTATE_CHANGED:
case POSITION_CHANGED:
mMediaSession.setPlaybackState(pmc);
break;
case META_CHANGED:
mMediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getArtistName())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getAlbumName())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, getTrackName())
//.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getAlbumCover())
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration())
.build());
break;
}
}
示例4: updateMetaData
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
/**
* 更新正在播放的音樂信息,切換歌曲時調用
*/
public void updateMetaData(String path) {
if (!StringUtils.isReal(path)) {
mMediaSession.setMetadata(null);
return;
}
SongInfo info = mediaManager.getSongInfo(context, path);
MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, info.getTitle())
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, info.getArtist())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, info.getAlbum())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, info.getArtist())
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getDuration())
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getCoverBitmap(info));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getCount());
}
mMediaSession.setMetadata(metaData.build());
}
示例5: updateMetadata
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
public void updateMetadata(String trackTitle, String artist, String album, BitmapDrawable albumImage) {
MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album)
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, trackTitle)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, -1);
if (albumImage != null) {
metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumImage.getBitmap());
}
mediaSession.setMetadata(metadataBuilder.build());
mediaSession.setActive(true);
// Put the service in the foreground, post notification
Helpers.createStopNotification(mediaSession, MediaRecorderService.this, MediaRecorderService.class, NOTIFICATION_ID);
// currently, only way to update Cast metadata is to re-send URL which causes reload of stream
//castMedia(trackTitle, artist, album, imageUrl);
}
示例6: getMetadata
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
public static MediaMetadataCompat getMetadata(Context ctx, String mediaId) {
MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
Bitmap albumArt = getAlbumBitmap(ctx, mediaId);
// Since MediaMetadataCompat is immutable, we need to create a copy to set the album art
// We don't set it initially on all items so that they don't take unnecessary memory
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
for (String key :
new String[]{
MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
MediaMetadataCompat.METADATA_KEY_ALBUM,
MediaMetadataCompat.METADATA_KEY_ARTIST,
MediaMetadataCompat.METADATA_KEY_GENRE,
MediaMetadataCompat.METADATA_KEY_TITLE
}) {
builder.putString(key, metadataWithoutBitmap.getString(key));
}
builder.putLong(
MediaMetadataCompat.METADATA_KEY_DURATION,
metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
return builder.build();
}
示例7: getMetadata
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
private MediaMetadataCompat getMetadata(Context context, Station station, String metaData) {
Bitmap stationImage = null;
// try to get station image
if (station != null && station.getStationImageFile() != null && station.getStationImageFile().exists()) {
stationImage = BitmapFactory.decodeFile(station.getStationImageFile().toString());
}
// use name of app as album title
String albumTitle = context.getResources().getString(R.string.app_name);
// log metadata change
LogHelper.v(LOG_TAG, "New Metadata available.");
if (station != null) {
return new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, station.getStationName())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, metaData)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, albumTitle)
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, stationImage)
.build();
} else {
return null;
}
}
示例8: getMetadata
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
private MediaMetadataCompat getMetadata(Context context, Station station, String metaData) {
Bitmap stationImage;
File imageFileRef = station.getStationImage(context);
if (imageFileRef != null && imageFileRef.exists()) {
// use station image
stationImage = BitmapFactory.decodeFile(imageFileRef.toString());
} else {
stationImage = null;
}
// use name of app as album title
String albumTitle = context.getResources().getString(R.string.app_name);
// log metadata change
LogHelper.i(LOG_TAG, "New Metadata available. Artist: " + station.TITLE + ", Title: " + metaData + ", Album: " + albumTitle);
return new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, station.TITLE)
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, metaData)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, albumTitle)
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, stationImage)
.build();
}
示例9: from
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
/**
* Build a notification using the information from the given media session. Makes heavy use
* of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
*
* @param context Context used to construct the notification.
* @param mediaSession Media session to get information.
* @return A pre-built notification with information from the given media session.
*/
static NotificationCompat.Builder from(
Context context, MediaSessionCompat mediaSession) {
MediaControllerCompat controller = mediaSession.getController();
MediaMetadataCompat mediaMetadata = controller.getMetadata();
MediaDescriptionCompat description = mediaMetadata.getDescription();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setSubText(description.getDescription())
.setLargeIcon(description.getIconBitmap())
.setContentIntent(controller.getSessionActivity())
.setDeleteIntent(
MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder;
}
示例10: onMetadataChanged
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
@Override
public void onMetadataChanged(final MediaMetadataCompat metadata) {
// Filtering out needless updates, given that the metadata has not changed.
if (isMediaIdSame(metadata, mState.getMediaMetadata())) {
Log.d(TAG, "onMetadataChanged: Filtering out needless onMetadataChanged() update");
return;
} else {
mState.setMediaMetadata(metadata);
}
performOnAllListeners(new ListenerCommand() {
@Override
public void perform(@NonNull MediaBrowserChangeListener listener) {
listener.onMetadataChanged(metadata);
}
});
}
示例11: cloneMetadataIfNeeded
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
private MediaMetadataCompat cloneMetadataIfNeeded(MediaMetadataCompat metadata) {
if (metadata == null) {
return null;
}
if (!metadata.containsKey(MediaMetadataCompat.METADATA_KEY_ART) && !metadata.containsKey(MediaMetadataCompat.METADATA_KEY_ALBUM_ART)) {
return metadata;
}
Builder builder = new Builder(metadata);
Bitmap artBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ART);
if (artBitmap != null) {
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, artBitmap.copy(artBitmap.getConfig(), false));
}
Bitmap albumArtBitmap = metadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART);
if (albumArtBitmap != null) {
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArtBitmap.copy(albumArtBitmap.getConfig(), false));
}
return builder.build();
}
示例12: iterator
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
@Override
public Iterator<MediaMetadataCompat> iterator(Context context) {
ContentResolver mResolver = context.getContentResolver();
ArrayList<Album> albums = MediaStoreHelper.loadAlbumList(mResolver, null, null, MediaStore.Audio.Albums.ALBUM);
ArrayList<Track> tracks = MediaStoreHelper.loadTrackList(mResolver, null, null, MediaStore.Audio.Media.TITLE);
ArrayList<MediaMetadataCompat> mediaList = new ArrayList<>();
for (Track track: tracks) {
for (Album album: albums) {
if (track.getAlbumId() == album.getId()) {
track.setAlbum(album);
}
}
mediaList.add(buildMediaFromTrack(track));
}
Collections.sort(mediaList, new Comparator<MediaMetadataCompat>() {
@Override
public int compare(MediaMetadataCompat m1, MediaMetadataCompat m2) {
String titleOfM1 = m1.getString(MediaMetadataCompat.METADATA_KEY_TITLE);
String titleOfM2 = m2.getString(MediaMetadataCompat.METADATA_KEY_TITLE);
return titleOfM1.compareTo(titleOfM2);
}
});
return mediaList.iterator();
}
示例13: getMetadata
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
public static MediaMetadataCompat getMetadata(String mediaId) {
MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
Bitmap albumArt = getAlbumBitmap(mediaId);
// Since MediaMetadataCompat is immutable, we need to create a copy to set the album art.
// We don't set it initially on all items so that they don't take unnecessary memory.
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
for (String key :
new String[]{
MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
MediaMetadataCompat.METADATA_KEY_ALBUM,
MediaMetadataCompat.METADATA_KEY_ARTIST,
MediaMetadataCompat.METADATA_KEY_GENRE,
MediaMetadataCompat.METADATA_KEY_TITLE
}) {
builder.putString(key, metadataWithoutBitmap.getString(key));
}
builder.putLong(
MediaMetadataCompat.METADATA_KEY_DURATION,
metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
return builder.build();
}
示例14: getMetadata
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
public static MediaMetadataCompat getMetadata(Context context, String mediaId) {
MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
Bitmap albumArt = getAlbumBitmap(context, mediaId);
// Since MediaMetadataCompat is immutable, we need to create a copy to set the album art.
// We don't set it initially on all items so that they don't take unnecessary memory.
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
for (String key :
new String[]{
MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
MediaMetadataCompat.METADATA_KEY_ALBUM,
MediaMetadataCompat.METADATA_KEY_ARTIST,
MediaMetadataCompat.METADATA_KEY_GENRE,
MediaMetadataCompat.METADATA_KEY_TITLE
}) {
builder.putString(key, metadataWithoutBitmap.getString(key));
}
builder.putLong(
MediaMetadataCompat.METADATA_KEY_DURATION,
metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
return builder.build();
}
示例15: createStopNotification
import android.support.v4.media.MediaMetadataCompat; //導入依賴的package包/類
public static void createStopNotification(MediaSessionCompat mediaSession, Service context, Class<?> serviceClass, int NOTIFICATION_ID) {
PendingIntent stopIntent = PendingIntent
.getService(context, 0, getIntent(MediaRecorderService.REQUEST_TYPE_STOP, context, serviceClass),
PendingIntent.FLAG_CANCEL_CURRENT);
MediaControllerCompat controller = mediaSession.getController();
MediaMetadataCompat mediaMetadata = controller.getMetadata();
MediaDescriptionCompat description = mediaMetadata.getDescription();
// Start foreground service to avoid unexpected kill
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setSubText(description.getDescription())
.setLargeIcon(description.getIconBitmap())
.setDeleteIntent(stopIntent)
// Add a pause button
.addAction(new android.support.v7.app.NotificationCompat.Action(
R.drawable.ic_stop_black_24dp, context.getString(R.string.stop),
MediaButtonReceiver.buildMediaButtonPendingIntent(context,
PlaybackStateCompat.ACTION_STOP)))
.setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
.setMediaSession(mediaSession.getSessionToken())
.setShowActionsInCompactView(0)
.setShowCancelButton(true)
.setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context,
PlaybackStateCompat.ACTION_STOP)))
.setSmallIcon(R.drawable.ic_album_black_24dp)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.build();
context.startForeground(NOTIFICATION_ID, notification);
}