本文整理汇总了Java中android.support.v4.media.MediaDescriptionCompat类的典型用法代码示例。如果您正苦于以下问题:Java MediaDescriptionCompat类的具体用法?Java MediaDescriptionCompat怎么用?Java MediaDescriptionCompat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaDescriptionCompat类属于android.support.v4.media包,在下文中一共展示了MediaDescriptionCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: from
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的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;
}
示例2: fetchImage
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
private void fetchImage(@NonNull MediaDescriptionCompat description)
{
String artUrl = null;
if (description.getIconUri() != null) {
artUrl = description.getIconUri().toString();
}
LogHelper.e(TAG, "fetchImage called ");
if (!TextUtils.equals(artUrl, mArtUrl)) {
mArtUrl = artUrl;
Picasso.with(getActivity())
.load(mArtUrl)
.centerCrop()
.fit()
.into(videoThumbnail);
}
}
示例3: createMediaItemAlbum
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@NonNull
private MediaItem createMediaItemAlbum(@NonNull final Cursor c) {
final MediaDescriptionCompat.Builder description = new MediaDescriptionCompat.Builder()
.setMediaId(MEDIA_ID_PREFIX_ALBUM.concat(c.getString(AlbumsProvider.COLUMN_ID)))
.setTitle(c.getString(AlbumsProvider.COLUMN_ALBUM));
final String art = c.getString(AlbumsProvider.COLUMN_ALBUM_ART);
if (!TextUtils.isEmpty(art)) {
final Uri uri = FileProvider.getUriForFile(mContext,
mContext.getPackageName().concat(".provider.album_thumbs"), new File(art));
for (final String p : mMediaBrowserCallerPackageNames) {
mContext.grantUriPermission(p, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
description.setIconUri(uri);
}
return new MediaItem(description.build(), MediaItem.FLAG_PLAYABLE);
}
示例4: onBindViewHolder
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
MediaDescriptionCompat description;
final CardViewHolder cardViewHolder = (CardViewHolder) viewHolder;
// Determine description and playing state of item based on instance type
cardViewHolder.setState(MediaItemViewHolder.STATE_NONE);
if (item instanceof MediaBrowserCompat.MediaItem) {
MediaBrowserCompat.MediaItem mediaItem = (MediaBrowserCompat.MediaItem) item;
LogHelper.d(TAG, "onBindViewHolder MediaItem: ", mediaItem.toString());
description = mediaItem.getDescription();
cardViewHolder.setState(MediaItemViewHolder.getMediaItemState(mContext, mediaItem));
} else if (item instanceof MediaSessionCompat.QueueItem) {
MediaSessionCompat.QueueItem queueItem = (MediaSessionCompat.QueueItem) item;
LogHelper.d(TAG, "onBindViewHolder QueueItem: ", queueItem.toString());
description = queueItem.getDescription();
if (QueueHelper.isQueueItemPlaying(mContext, queueItem)) {
cardViewHolder.setState(MediaItemViewHolder.getStateFromController(mContext));
}
} else {
throw new IllegalArgumentException("Object must be MediaItem or QueueItem, not "
+ item.getClass().getSimpleName());
}
cardViewHolder.setupCardView(mContext, description);
}
示例5: notificationBuilder
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
private NotificationCompat.Builder notificationBuilder(PlayerService context, MediaSessionCompat session) {
MediaControllerCompat controller = session.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(mediaMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ART))
.setContentIntent(clickIntent)
.setDeleteIntent(
MediaButtonReceiver.buildMediaButtonPendingIntent(context, receiverName, PlaybackStateCompat.ACTION_STOP))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder;
}
示例6: onLoadChildren
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@Override
public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
ChannelDatabase channelDatabase = ChannelDatabase.getInstance(getApplicationContext());
if (parentId.equals(MEDIA_ROOT_ID)) {
try {
for (Channel channel : channelDatabase.getChannels()) {
MediaDescriptionCompat descriptionCompat = new MediaDescriptionCompat.Builder()
.setMediaId(channel.getInternalProviderData().getVideoUrl())
.setTitle(channel.getDisplayName())
.setIconUri(Uri.parse(channel.getChannelLogo()))
.setSubtitle(getString(R.string.channel_no_xxx, channel.getDisplayNumber()))
.setDescription(channel.getDescription())
.setMediaUri(Uri.parse(channel.getInternalProviderData().getVideoUrl()))
.build();
mediaItems.add(new MediaBrowserCompat.MediaItem(descriptionCompat,
MediaBrowserCompat.MediaItem.FLAG_PLAYABLE));
}
result.sendResult(mediaItems);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
示例7: QueueItem
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
private QueueItem(Object obj, MediaDescriptionCompat mediadescriptioncompat, long l)
{
if (mediadescriptioncompat == null)
{
throw new IllegalArgumentException("Description cannot be null.");
}
if (l == -1L)
{
throw new IllegalArgumentException("Id cannot be QueueItem.UNKNOWN_ID");
} else
{
mDescription = mediadescriptioncompat;
mId = l;
mItem = obj;
return;
}
}
示例8: onLoad
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@Override
protected void onLoad(Bundle savedInstanceState) {
super.onLoad(savedInstanceState);
subscriptions.clear();
MediaDescriptionCompat desc = queueItem.getDescription();
getView().trackTitle.setText(desc.getTitle());
getView().artistName.setText(desc.getSubtitle());
Bitmap artwork = desc.getIconBitmap();
Uri artworkUri = desc.getIconUri();
if (artwork != null) {
getView().artworkThumbnail.setImageBitmap(artwork);
} else if (artworkUri != null) {
artworkReqestor.newRequest(artworkUri, getView().artworkThumbnail, null);
} else {
getView().artworkThumbnail.setImageResource(R.drawable.default_artwork);
}
updatePlayBtn();
subscribeBroadcasts();
}
示例9: onBindViewHolder
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
QueueItem item = getItem(position);
holder.reset();
MediaDescriptionCompat desc = item.getDescription();
holder.title.setText(desc.getTitle());
holder.subtitle.setText(desc.getSubtitle());
Uri uri = desc.getIconUri();
if (uri != null) {
ArtInfo artInfo = ArtInfo.fromUri(uri);
if (artInfo !=ArtInfo.NULLINSTANCE) {
requestor.newRequest(artInfo, holder.artwork, BundleHelper.b().putInt(1).get());
} else {
CharSequence titlee = desc.getTitle();
setLetterTileDrawable(holder, titlee != null ? titlee.toString() : "");
}
}
setItemActive(holder, item);
}
示例10: testAddNext
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@Test
public void testAddNext() {
List<Uri> queue = new ArrayList<>(5);
List<MediaDescriptionCompat> descriptions = new ArrayList<>(5);
for (int ii=0; ii<5; ii++) {
Uri uri = Uri.parse("content://test2/track/" + ii);
queue.add(uri);
MediaDescriptionCompat desc = mock(MediaDescriptionCompat.class);
when(desc.getMediaId()).thenReturn(uri.toString());
descriptions.add(desc);
}
when(mClient.getDescriptions(queue)).thenReturn(Observable.just(descriptions));
mPlaybackQueue.addNext(queue);
verify(mClient).getDescriptions(queue);
checkListsMatch(mPlaybackQueue.get(), mPlaybackQueue.getQueueItems(), 15);
assertThat(mPlaybackQueue.getCurrentPos()).isEqualTo(mInitialPosition);
assertThat(mPlaybackQueue.get().get(mInitialPosition)).isEqualTo(mInitialQueue.get(mInitialPosition));
assertThat(mPlaybackQueue.getNextPos()).isEqualTo(mInitialPosition + 1);
assertThat(mPlaybackQueue.get().get(mPlaybackQueue.getNextPos())).isEqualTo(queue.get(0));
assertThat(mPlaybackQueue.getPreviousPos()).isEqualTo(mInitialPosition - 1);
assertThat(mPlaybackQueue.get().get(mPlaybackQueue.getPreviousPos())).isEqualTo(mInitialQueue.get(mInitialPosition - 1));
verify(mListener).onCurrentPosChanged();
verify(mListener).onQueueChanged();
}
示例11: testReplace_updatesCurrentToNewPos
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@Test
public void testReplace_updatesCurrentToNewPos() {
List<Uri> queue = new ArrayList<>(10);
List<MediaDescriptionCompat> descriptions = new ArrayList<>(10);
for (int ii=0; ii<10; ii++) {
Uri uri = Uri.parse("content://test2/track/" + ii);
queue.add(uri);
MediaDescriptionCompat desc = mock(MediaDescriptionCompat.class);
when(desc.getMediaId()).thenReturn(uri.toString());
descriptions.add(desc);
}
when(mClient.getDescriptions(queue)).thenReturn(Observable.just(descriptions));
mPlaybackQueue.replace(queue, 4);
verify(mClient).getDescriptions(queue);
checkListsMatch(mPlaybackQueue.get(), mPlaybackQueue.getQueueItems(), 10);
assertThat(mPlaybackQueue.get()).isEqualTo(queue);
assertThat(mPlaybackQueue.getCurrentPos()).isEqualTo(4);
assertThat(mPlaybackQueue.getNextPos()).isEqualTo(5);
assertThat(mPlaybackQueue.getPreviousPos()).isEqualTo(3);
verify(mListener, times(2)).onCurrentPosChanged();
verify(mListener, never()).onQueueChanged();
}
示例12: getAutoRoots
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
@Override
public List<MediaDescriptionCompat> getAutoRoots() {
Pair[] roots = new Pair[] {
Pair.of(IndexUris.albums(indexAuthority), R.string.title_albums),
Pair.of(IndexUris.artists(indexAuthority), R.string.title_artists),
Pair.of(IndexUris.genres(indexAuthority), R.string.title_genres),
Pair.of(IndexUris.playlists(indexAuthority), R.string.title_playlists)
};
List<MediaDescriptionCompat> list = new ArrayList<>(roots.length);
for (Pair p : roots) {
list.add(new MediaDescriptionCompat.Builder()
.setMediaId(p.getLeft().toString())
.setTitle(appContext.getString((int)p.getRight()))
.build());
}
return list;
}
示例13: createStopNotification
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的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);
}
示例14: getQueueItem
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
private MediaSessionCompat.QueueItem getQueueItem(Video v) {
MediaDescriptionCompat desc = new MediaDescriptionCompat.Builder()
.setDescription(v.description)
.setMediaId(v.id + "")
.setIconUri(Uri.parse(v.cardImageUrl))
.setMediaUri(Uri.parse(v.videoUrl))
.setSubtitle(v.studio)
.setTitle(v.title)
.build();
return new MediaSessionCompat.QueueItem(desc, v.id);
}
示例15: QueueItem
import android.support.v4.media.MediaDescriptionCompat; //导入依赖的package包/类
private QueueItem(Object queueItem, MediaDescriptionCompat description, long id) {
if (description == null) {
throw new IllegalArgumentException("Description cannot be null.");
} else if (id == -1) {
throw new IllegalArgumentException("Id cannot be QueueItem.UNKNOWN_ID");
} else {
this.mDescription = description;
this.mId = id;
this.mItem = queueItem;
}
}