android.support.v4.media.MediaDescriptionCompat Java Examples
The following examples show how to use
android.support.v4.media.MediaDescriptionCompat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoteControlClientLP.java From Popeens-DSub with GNU General Public License v3.0 | 7 votes |
@Override public void updatePlaylist(List<DownloadFile> playlist) { List<MediaSessionCompat.QueueItem> queue = new ArrayList<>(); for(DownloadFile file: playlist) { Entry entry = file.getSong(); Bundle extras = new Bundle(); extras.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, ((entry.getDuration() == null) ? 0 : (entry.getDuration() * 1000))); MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(entry.getId()) .setTitle(entry.getTitle()) .setSubtitle(entry.getArtist()) .setDescription(entry.getAlbum()) .setExtras(extras) .build(); MediaSessionCompat.QueueItem item = new MediaSessionCompat.QueueItem(description, entry.getId().hashCode()); queue.add(item); } mediaSession.setQueue(queue); currentQueue = playlist; }
Example #2
Source File: AutoMusicProvider.java From VinylMusicPlayer with GNU General Public License v3.0 | 6 votes |
private MediaBrowserCompat.MediaItem createPlayableMediaItem(String mediaId, Uri musicSelection, String title, @Nullable String subtitle, @Nullable Bitmap albumArt, @Nullable Resources resources) { MediaDescriptionCompat.Builder builder = new MediaDescriptionCompat.Builder(); builder.setMediaId(AutoMediaIDHelper.createMediaID(musicSelection.getPathSegments().get(PATH_SEGMENT_ID), mediaId)) .setTitle(title); if (subtitle != null) { builder.setSubtitle(subtitle); } if (resources != null) { if (albumArt != null) { builder.setIconBitmap(albumArt); } else { builder.setIconUri(defaultAlbumArtUri); } } return new MediaBrowserCompat.MediaItem(builder.build(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE); }
Example #3
Source File: TtsService.java From android-app with GNU General Public License v3.0 | 6 votes |
private NotificationCompat.Builder generateNotificationBuilderFrom( Context context, MediaSessionCompat mediaSession) { NotificationCompat.Builder builder = new NotificationCompat.Builder( context, NotificationsHelper.CHANNEL_ID_TTS) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setDeleteIntent(generateActionIntent(PlaybackStateCompat.ACTION_STOP)); if (mediaSession != null) { MediaControllerCompat controller = mediaSession.getController(); builder.setContentIntent(controller.getSessionActivity()); MediaMetadataCompat mediaMetadata = controller.getMetadata(); if (mediaMetadata != null) { MediaDescriptionCompat description = mediaMetadata.getDescription(); builder.setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()) .setSubText(description.getDescription()) .setLargeIcon(description.getIconBitmap()); } } return builder; }
Example #4
Source File: NotificationUtil.java From Prodigal with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: AbstractSongDirectory.java From Jockey with Apache License 2.0 | 6 votes |
private List<MediaBrowserCompat.MediaItem> convertSongsToMediaItems(List<Song> songs) { List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>(); for (int i = 0; i < songs.size(); i++) { Song song = songs.get(i); mediaItems.add(new MediaBrowserCompat.MediaItem( new MediaDescriptionCompat.Builder() .setMediaId(getIdForSong(song, i)) .setTitle(song.getSongName()) .setSubtitle(song.getArtistName()) .setDescription(song.getAlbumName()) .setMediaUri(song.getLocation()) .build(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE)); } return mediaItems; }
Example #6
Source File: MediaBrowserImpl.java From PainlessMusicPlayer with Apache License 2.0 | 6 votes |
@NonNull private MediaItem createMediaItemAlbum(@NonNull final Cursor c) { final MediaDescriptionCompat.Builder description = new MediaDescriptionCompat.Builder() .setMediaId(MediaBrowserConstants.MEDIA_ID_PREFIX_ALBUM .concat(c.getString(AlbumsProviderKt.COLUMN_ID))) .setTitle(c.getString(AlbumsProviderKt.COLUMN_ALBUM)); final String art = c.getString(AlbumsProviderKt.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); }
Example #7
Source File: AutoMediaBrowserService.java From Popeens-DSub with GNU General Public License v3.0 | 6 votes |
private void getPodcasts(final Result<List<MediaBrowserCompat.MediaItem>> result) { new SilentServiceTask<List<PodcastChannel>>(downloadService) { @Override protected List<PodcastChannel> doInBackground(MusicService musicService) throws Throwable { return musicService.getPodcastChannels(false, downloadService, null); } @Override protected void done(List<PodcastChannel> podcasts) { List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>(); for(PodcastChannel podcast: podcasts) { MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setTitle(podcast.getName()) .setMediaId(PODCAST_PREFIX + podcast.getId()) .build(); mediaItems.add(new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE)); } result.sendResult(mediaItems); } }.execute(); result.detach(); }
Example #8
Source File: AutoMediaBrowserService.java From Popeens-DSub with GNU General Public License v3.0 | 6 votes |
private void getPlaylists(final Result<List<MediaBrowserCompat.MediaItem>> result) { new SilentServiceTask<List<Playlist>>(downloadService) { @Override protected List<Playlist> doInBackground(MusicService musicService) throws Throwable { return musicService.getPlaylists(false, downloadService, null); } @Override protected void done(List<Playlist> playlists) { List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>(); for(Playlist playlist: playlists) { MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setTitle(playlist.getName()) .setMediaId(PLAYLIST_PREFIX + playlist.getId()) .build(); mediaItems.add(new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE)); } result.sendResult(mediaItems); } }.execute(); result.detach(); }
Example #9
Source File: MediaStyleHelper.java From AndroidAudioExample with MIT License | 6 votes |
/** * 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; }
Example #10
Source File: AutoMediaBrowserService.java From Popeens-DSub with GNU General Public License v3.0 | 6 votes |
private void getLibrary(final Result<List<MediaBrowserCompat.MediaItem>> result) { new SilentServiceTask<List<MusicFolder>>(downloadService) { @Override protected List<MusicFolder> doInBackground(MusicService musicService) throws Throwable { return musicService.getMusicFolders(false, downloadService, null); } @Override protected void done(List<MusicFolder> folders) { List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>(); for(MusicFolder folder: folders) { MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setTitle(folder.getName()) .setMediaId(MUSIC_FOLDER_PREFIX + folder.getId()) .build(); mediaItems.add(new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE)); } result.sendResult(mediaItems); } }.execute(); result.detach(); }
Example #11
Source File: CumulusBrowseService.java From CumulusTV with MIT License | 6 votes |
@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(); } } }
Example #12
Source File: PlaybackControlsFragment.java From YouTube-In-Background with MIT License | 6 votes |
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, this.artUrl)) { this.artUrl = artUrl; Picasso.with(activity) .load(this.artUrl) .centerCrop() .fit() .into(videoThumbnail); } }
Example #13
Source File: AutoMediaBrowserService.java From Popeens-DSub with GNU General Public License v3.0 | 6 votes |
private void getAlbumLists(Result<List<MediaBrowserCompat.MediaItem>> result) { List<Integer> albums = new ArrayList<>(); albums.add(R.string.main_albums_newest); albums.add(R.string.main_albums_random); if(!Util.isTagBrowsing(downloadService)) { albums.add(R.string.main_albums_highest); } albums.add(R.string.main_albums_starred); albums.add(R.string.main_albums_recent); List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>(); for(Integer id: albums) { MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setTitle(downloadService.getResources().getString(id)) .setMediaId(ALBUM_TYPE_PREFIX + id) .build(); mediaItems.add(new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE)); } result.sendResult(mediaItems); }
Example #14
Source File: MediaBrowserDirectory.java From Jockey with Apache License 2.0 | 6 votes |
private MediaItem makeRelative(MediaItem item, String idPrefix) { MediaDescriptionCompat mediaDescription = item.getDescription(); return new MediaItem( new MediaDescriptionCompat.Builder() .setMediaId(idPrefix + mediaDescription.getMediaId()) .setTitle(mediaDescription.getTitle()) .setSubtitle(mediaDescription.getSubtitle()) .setDescription(mediaDescription.getDescription()) .setIconBitmap(mediaDescription.getIconBitmap()) .setIconUri(mediaDescription.getIconUri()) .setExtras(mediaDescription.getExtras()) .setMediaUri(mediaDescription.getMediaUri()) .build(), item.getFlags() ); }
Example #15
Source File: FullScreenPlayerActivity.java From LyricHere with Apache License 2.0 | 5 votes |
private void updateMediaDescription(MediaDescriptionCompat description) { if (description == null) { return; } LogUtils.d(TAG, "updateMediaDescription called "); mLine1.setText(description.getTitle()); mLine2.setText(description.getSubtitle()); fetchImageAsync(description); }
Example #16
Source File: MediaBrowserImpl.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@NonNull private MediaItem createBrowsableMediaItemCurrentQueue() { final MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(MEDIA_ID_CURENT_QUEUE) .setTitle(mContext.getText(R.string.Now_Playing)) .build(); return new MediaItem(description, MediaItem.FLAG_BROWSABLE); }
Example #17
Source File: MediaBrowserImpl.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@NonNull private MediaItem createBrowsableMediaItemRecentAlbums() { final MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(MEDIA_ID_RECENT_ALBUMS) .setTitle(mContext.getText(R.string.Recently_played_albums)) .build(); return new MediaItem(description, MediaItem.FLAG_BROWSABLE); }
Example #18
Source File: MediaBrowserImpl.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@NonNull private MediaItem createMediaItemRecent() { final MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(MediaBrowserConstants.MEDIA_ID_RECENT) .setTitle(mContext.getText(R.string.Recently_added)) .build(); return new MediaItem(description, MediaItem.FLAG_PLAYABLE); }
Example #19
Source File: MediaBrowserImpl.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@NonNull private MediaItem createMediaItemMedia(@NonNull final Media media) { final MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(Long.toString(media.getId())) .setTitle(media.getTitle()) .setSubtitle(media.getArtist()) .build(); return new MediaItem(description, MediaItem.FLAG_PLAYABLE); }
Example #20
Source File: FullScreenPlayerActivity.java From LyricHere with Apache License 2.0 | 5 votes |
private void updateFromParams(Intent intent) { if (intent != null) { MediaDescriptionCompat description = intent.getParcelableExtra( MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION); if (description != null) { updateMediaDescription(description); } } }
Example #21
Source File: MediaBrowserImpl.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@NonNull private MediaItem createMediaItemGenre(@NonNull final Cursor c) { final MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(MediaBrowserConstants.MEDIA_ID_PREFIX_GENRE.concat( c.getString(GenresProviderKt.COLUMN_ID))) .setTitle(c.getString(GenresProviderKt.COLUMN_NAME)) .build(); return new MediaItem(description, MediaItem.FLAG_PLAYABLE); }
Example #22
Source File: MediaBrowserImpl.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@NonNull private MediaItem createMediaItemRandom() { final MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(MediaBrowserConstants.MEDIA_ID_RANDOM) .setTitle(mContext.getText(R.string.Random_playlist)) .build(); return new MediaItem(description, MediaItem.FLAG_PLAYABLE); }
Example #23
Source File: MediaStyleHelper.java From Jockey with Apache License 2.0 | 5 votes |
/** * Build a notification using the information from the given media session. * @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. */ public static NotificationCompat.Builder from(Context context, MediaSessionCompat mediaSession, String channel) { MediaControllerCompat controller = mediaSession.getController(); MediaMetadataCompat mediaMetadata = controller.getMetadata(); MediaDescriptionCompat description = mediaMetadata.getDescription(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channel); builder .setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()) .setSubText(description.getDescription()) .setContentIntent(controller.getSessionActivity()) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setWhen(0) .setShowWhen(false); if (description.getIconBitmap() == null || description.getIconBitmap().isRecycled()) { builder.setLargeIcon( BitmapFactory.decodeResource(context.getResources(), R.drawable.art_default)); } else { builder.setLargeIcon(description.getIconBitmap()); } return builder; }
Example #24
Source File: MediaNotificationManager.java From YouTube-In-Background with MIT License | 5 votes |
private PendingIntent createContentIntent(MediaDescriptionCompat description) { Intent openUI = new Intent(exoAudioService, MainActivity.class); openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); openUI.putExtra(Config.EXTRA_START_FULLSCREEN, true); if (description != null) { openUI.putExtra(Config.EXTRA_CURRENT_MEDIA_DESCRIPTION, description); } return PendingIntent.getActivity(exoAudioService, REQUEST_CODE, openUI, FLAG_CANCEL_CURRENT); }
Example #25
Source File: PlaybackControlsFragment.java From YouTube-In-Background with MIT License | 5 votes |
private void updateMediaDescription(MediaDescriptionCompat description) { if (description == null) { return; } // LogHelper.e(TAG, "updateMediaDescription called "); videoTitle.setText(description.getTitle()); videoViewsNumber.setText(description.getSubtitle()); fetchImage(description); }
Example #26
Source File: AbstractSongDirectory.java From Jockey with Apache License 2.0 | 5 votes |
@Override protected final Single<List<MediaBrowserCompat.MediaItem>> getMedia() { return getSongs().map(this::convertSongsToMediaItems).map(mediaItems -> { mediaItems.add(0, new MediaBrowserCompat.MediaItem( new MediaDescriptionCompat.Builder() .setMediaId(ENTRY_SHUFFLE_ALL) .setTitle(mContext.getString(R.string.action_shuffle_all)) .build(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE)); return mediaItems; }); }
Example #27
Source File: MediaBrowserDirectory.java From Jockey with Apache License 2.0 | 5 votes |
public MediaItem getDirectory(Context context) { return new MediaItem( new MediaDescriptionCompat.Builder() .setMediaId(getPath()) .setTitle(getName(context)) .build(), MediaItem.FLAG_BROWSABLE); }
Example #28
Source File: AutoMusicProvider.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
private MediaBrowserCompat.MediaItem createPlayableMediaItem(String mediaId, String title, int iconDrawableId, @Nullable String subtitle) { MediaDescriptionCompat.Builder builder = new MediaDescriptionCompat.Builder() .setMediaId(mediaId) .setTitle(title) .setIconBitmap(ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(mContext, iconDrawableId, ThemeStore.textColorSecondary(mContext)))); if (subtitle != null) { builder.setSubtitle(subtitle); } return new MediaBrowserCompat.MediaItem(builder.build(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE); }
Example #29
Source File: Samples.java From googleads-ima-android with Apache License 2.0 | 5 votes |
public static MediaDescriptionCompat getMediaDescription(Context context, Sample sample) { Bundle extras = new Bundle(); Bitmap bitmap = getBitmap(context, sample.bitmapResource); extras.putParcelable(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap); extras.putParcelable(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap); return new MediaDescriptionCompat.Builder() .setMediaId(sample.mediaId) .setIconBitmap(bitmap) .setTitle(sample.title) .setDescription(sample.description) .setExtras(extras) .build(); }
Example #30
Source File: MediaNotificationManager.java From LyricHere with Apache License 2.0 | 5 votes |
private PendingIntent createContentIntent(MediaDescriptionCompat description) { Intent openUI = new Intent(mService, MusicPlayerActivity.class); openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); openUI.putExtra(MusicPlayerActivity.EXTRA_START_FULLSCREEN, true); if (description != null) { openUI.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, description); } return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT); }