List of usage examples for android.media MediaMetadata METADATA_KEY_ARTIST
String METADATA_KEY_ARTIST
To view the source code for android.media MediaMetadata METADATA_KEY_ARTIST.
Click Source Link
From source file:com.chinaftw.music.model.MusicProvider.java
/** * Very basic implementation of a search that filter music tracks with artist containing * the given query./*from ww w . j a v a2 s .c o m*/ * */ public Iterable<MediaMetadata> searchMusicByArtist(String query) { return searchMusic(MediaMetadata.METADATA_KEY_ARTIST, query); }
From source file:com.example.android.mediabrowserservice.model.MusicProvider.java
private MediaMetadata buildFromJSON(JSONObject json, String basePath) throws JSONException { String title = json.getString(JSON_TITLE); String album = json.getString(JSON_ALBUM); String artist = json.getString(JSON_ARTIST); String genre = json.getString(JSON_GENRE); String source = json.getString(JSON_SOURCE); String iconUrl = json.getString(JSON_IMAGE); int trackNumber = json.getInt(JSON_TRACK_NUMBER); int totalTrackCount = json.getInt(JSON_TOTAL_TRACK_COUNT); int duration = json.getInt(JSON_DURATION) * 1000; // ms LogHelper.d(TAG, "Found music track: ", json); // Media is stored relative to JSON file if (!source.startsWith("http")) { source = basePath + source;/* w w w . java2 s . com*/ } if (!iconUrl.startsWith("http")) { iconUrl = basePath + iconUrl; } // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. String id = String.valueOf(source.hashCode()); // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. return new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id) .putString(CUSTOM_METADATA_TRACK_SOURCE, source).putString(MediaMetadata.METADATA_KEY_ALBUM, album) .putString(MediaMetadata.METADATA_KEY_ARTIST, artist) .putLong(MediaMetadata.METADATA_KEY_DURATION, duration) .putString(MediaMetadata.METADATA_KEY_GENRE, genre) .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadata.METADATA_KEY_TITLE, title) .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); }
From source file:com.chinaftw.music.model.MusicProvider.java
private MediaMetadata buildFromJSON(JSONObject json) throws JSONException { String id = String.valueOf(json.getInt(JSON_SONG_ID)); String title = json.getString(JSON_TITLE); String album = json.getJSONObject(JSON_ALBUM).getString(JSON_ALBUM_NAME); String albumId = json.getJSONObject(JSON_ALBUM).getString(JSON_ALBUM_ID); String artist = json.getJSONArray(JSON_ARTIST).getJSONObject(0).getString(JSON_ARTIST_NAME); String artistId = json.getJSONObject(JSON_ALBUM).getString(JSON_ARTIST_ID); String imageId = json.getJSONObject(JSON_ALBUM).getString(JSON_ALBUM_IMAGE_ID); int duration = json.getInt(JSON_DURATION); // ms LogHelper.d(TAG, "Found music track: ", json); String source = MusicAPI.getSongUrl(id); String imageUri = MusicAPI.getPictureUrl(imageId); // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. return new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id) .putString(CUSTOM_METADATA_TRACK_SOURCE, source).putString(MediaMetadata.METADATA_KEY_ALBUM, album) .putString(MediaMetadata.METADATA_KEY_ARTIST, artist) .putLong(MediaMetadata.METADATA_KEY_DURATION, duration) .putString(MediaMetadata.METADATA_KEY_GENRE, "BILLBOARD") //TODO .putString(MediaMetadata.METADATA_KEY_TITLE, title) .putString(MediaMetadata.METADATA_KEY_ART_URI, imageUri) .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, imageUri) .putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, imageUri).build(); }
From source file:robert843.o2.pl.player.model.MusicProvider.java
private MediaMetadata buildFromJSON(String ytId) throws JSONException, ParserConfigurationException, IOException { String title = ""; String artist = ""; String source = ""; String iconUrl = ""; String site = "yt"; int duration = 0; // ms LogHelper.d(TAG, "Found music track: ", ytId); // Media is stored relative to JSON file if (site.contains("yt")) { MovieParser parser = new MovieParser(ytId); parser.parse();/*from w w w . j av a 2s . c om*/ source = "" + parser.getUrl(); duration = parser.getLength() * 1000; iconUrl = parser.getAlbumUrl(); System.out.println(iconUrl); title = parser.getTitle(); artist = parser.getChanelName(); } // Since we don't have a unique ID in the server, we fake one using the hashcode of // the music source. In a real world app, this could come from the server. String id = String.valueOf(source.hashCode()); // Adding the music source to the MediaMetadata (and consequently using it in the // mediaSession.setMetadata) is not a good idea for a real world music app, because // the session metadata can be accessed by notification listeners. This is done in this // sample for convenience only. return new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id) // .putString(CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadata.METADATA_KEY_ARTIST, artist).putString("id", ytId) .putLong(MediaMetadata.METADATA_KEY_DURATION, duration) .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadata.METADATA_KEY_TITLE, title).build(); }
From source file:de.rwth_aachen.comsys.audiosync.model.MusicProvider.java
private void createLocal(String file) { MediaMetadata item = new MediaMetadata.Builder() .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, LOCAL_PREFIX + file) .putString(CUSTOM_METADATA_TRACK_SOURCE, "https://dl.dropboxusercontent.com/u/58908793/" + file) .putString(CUSTOM_METADATA_ASSET_FILE, file).putString(MediaMetadata.METADATA_KEY_ALBUM, "Demo") .putString(MediaMetadata.METADATA_KEY_ARTIST, "Simon G") .putLong(MediaMetadata.METADATA_KEY_DURATION, 304000) .putString(MediaMetadata.METADATA_KEY_GENRE, "Testing") .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, "https://upload.wikimedia.org/wikipedia/commons/0/02/Metr%C3%B3nomo_digital_Korg_MA-30.jpg") .putString(MediaMetadata.METADATA_KEY_TITLE, file) .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, 1) .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, 1).build(); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); }
From source file:uk.org.ngo.squeezer.service.SqueezeService.java
/** * Manages the state of any ongoing notification based on the player and connection state. *//* ww w . jav a 2s . c o m*/ private void updateOngoingNotification() { Player activePlayer = this.mActivePlayer.get(); PlayerState activePlayerState = getActivePlayerState(); // Update scrobble state, if either we're currently scrobbling, or we // were (to catch the case where we started scrobbling a song, and the // user went in to settings to disable scrobbling). if (scrobblingEnabled || scrobblingPreviouslyEnabled) { scrobblingPreviouslyEnabled = scrobblingEnabled; Scrobble.scrobbleFromPlayerState(this, activePlayerState); } // If there's no active player then kill the notification and get out. // TODO: Have a "There are no connected players" notification text. if (activePlayer == null || activePlayerState == null) { clearOngoingNotification(); return; } boolean playing = activePlayerState.isPlaying(); // If the song is not playing and the user wants notifications only when playing then // kill the notification and get out. if (!playing && !mShowNotificationWhenNotPlaying) { clearOngoingNotification(); return; } // If there's no current song then kill the notification and get out. // TODO: Have a "There's nothing playing" notification text. final Song currentSong = activePlayerState.getCurrentSong(); if (currentSong == null) { clearOngoingNotification(); return; } // Compare the current state with the state when the notification was last updated. // If there are no changes (same song, same playing state) then there's nothing to do. String songName = currentSong.getName(); String albumName = currentSong.getAlbumName(); String artistName = currentSong.getArtist(); Uri url = currentSong.getArtworkUrl(); String playerName = activePlayer.getName(); if (mNotifiedPlayerState == null) { mNotifiedPlayerState = new PlayerState(); } else { boolean lastPlaying = mNotifiedPlayerState.isPlaying(); Song lastNotifiedSong = mNotifiedPlayerState.getCurrentSong(); // No change in state if (playing == lastPlaying && currentSong.equals(lastNotifiedSong)) { return; } } mNotifiedPlayerState.setCurrentSong(currentSong); mNotifiedPlayerState.setPlayStatus(activePlayerState.getPlayStatus()); final NotificationManagerCompat nm = NotificationManagerCompat.from(this); PendingIntent nextPendingIntent = getPendingIntent(ACTION_NEXT_TRACK); PendingIntent prevPendingIntent = getPendingIntent(ACTION_PREV_TRACK); PendingIntent playPendingIntent = getPendingIntent(ACTION_PLAY); PendingIntent pausePendingIntent = getPendingIntent(ACTION_PAUSE); PendingIntent closePendingIntent = getPendingIntent(ACTION_CLOSE); Intent showNowPlaying = new Intent(this, NowPlayingActivity.class) .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent pIntent = PendingIntent.getActivity(this, 0, showNowPlaying, 0); Notification notification; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final Notification.Builder builder = new Notification.Builder(this); builder.setContentIntent(pIntent); builder.setSmallIcon(R.drawable.squeezer_notification); builder.setVisibility(Notification.VISIBILITY_PUBLIC); builder.setShowWhen(false); builder.setContentTitle(songName); builder.setContentText(albumName); builder.setSubText(playerName); builder.setStyle(new Notification.MediaStyle().setShowActionsInCompactView(1, 2) .setMediaSession(mMediaSession.getSessionToken())); final MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder(); metaBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, artistName); metaBuilder.putString(MediaMetadata.METADATA_KEY_ALBUM, albumName); metaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, songName); mMediaSession.setMetadata(metaBuilder.build()); // Don't set an ongoing notification, otherwise wearable's won't show it. builder.setOngoing(false); builder.setDeleteIntent(closePendingIntent); if (playing) { builder.addAction( new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_pause, "Pause", pausePendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent)); } else { builder.addAction( new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_play, "Play", playPendingIntent)) .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent)); } ImageFetcher.getInstance(this).loadImage(url, getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height), new ImageWorker.ImageWorkerCallback() { @Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void process(Object data, @Nullable Bitmap bitmap) { if (bitmap == null) { bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_album_noart); } metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap); metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); mMediaSession.setMetadata(metaBuilder.build()); builder.setLargeIcon(bitmap); nm.notify(PLAYBACKSERVICE_STATUS, builder.build()); } }); } else { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setOngoing(true); builder.setCategory(NotificationCompat.CATEGORY_SERVICE); builder.setSmallIcon(R.drawable.squeezer_notification); RemoteViews normalView = new RemoteViews(this.getPackageName(), R.layout.notification_player_normal); RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_player_expanded); normalView.setOnClickPendingIntent(R.id.next, nextPendingIntent); expandedView.setOnClickPendingIntent(R.id.previous, prevPendingIntent); expandedView.setOnClickPendingIntent(R.id.next, nextPendingIntent); builder.setContent(normalView); normalView.setTextViewText(R.id.trackname, songName); normalView.setTextViewText(R.id.albumname, albumName); expandedView.setTextViewText(R.id.trackname, songName); expandedView.setTextViewText(R.id.albumname, albumName); expandedView.setTextViewText(R.id.player_name, playerName); if (playing) { normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause); normalView.setOnClickPendingIntent(R.id.pause, pausePendingIntent); expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause); expandedView.setOnClickPendingIntent(R.id.pause, pausePendingIntent); } else { normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_play); normalView.setOnClickPendingIntent(R.id.pause, playPendingIntent); expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_play); expandedView.setOnClickPendingIntent(R.id.pause, playPendingIntent); } builder.setContentTitle(songName); builder.setContentText(getString(R.string.notification_playing_text, playerName)); builder.setContentIntent(pIntent); notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.bigContentView = expandedView; } nm.notify(PLAYBACKSERVICE_STATUS, notification); ImageFetcher.getInstance(this).loadImage(this, url, normalView, R.id.album, getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_width), getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_height), nm, PLAYBACKSERVICE_STATUS, notification); ImageFetcher.getInstance(this).loadImage(this, url, expandedView, R.id.album, getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_width), getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_height), nm, PLAYBACKSERVICE_STATUS, notification); } }
From source file:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java
private void updateMetadata(final Video video) { final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder(); metadataBuilder.putString(MediaMetadata.METADATA_KEY_MEDIA_ID, video.id + ""); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, video.title); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, video.studio); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_DESCRIPTION, video.description); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, video.cardImageUrl); metadataBuilder.putLong(MediaMetadata.METADATA_KEY_DURATION, mDuration); // And at minimum the title and artist for legacy support metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, video.title); metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, video.studio); Glide.with(this).load(Uri.parse(video.cardImageUrl)).asBitmap().into(new SimpleTarget<Bitmap>(500, 500) { @Override/*from w w w. ja v a2 s .co m*/ public void onResourceReady(Bitmap bitmap, GlideAnimation anim) { metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); mSession.setMetadata(metadataBuilder.build()); } }); }
From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java
private void updateMetadata(final VideoModel videoModel) { final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder(); metadataBuilder.putString(MediaMetadata.METADATA_KEY_MEDIA_ID, videoModel.id + ""); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, videoModel.title); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, videoModel.studio); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_DESCRIPTION, videoModel.description); metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, videoModel.cardImageUrl); metadataBuilder.putLong(MediaMetadata.METADATA_KEY_DURATION, mDuration); // And at minimum the title and artist for legacy support metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, videoModel.title); metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, videoModel.studio); Glide.with(this).load(Uri.parse(videoModel.cardImageUrl)).asBitmap() .into(new SimpleTarget<Bitmap>(500, 500) { @Override/* www. j a va 2s.c o m*/ public void onResourceReady(Bitmap bitmap, GlideAnimation anim) { metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); mSession.setMetadata(metadataBuilder.build()); } }); }
From source file:com.av.remusic.service.MediaService.java
private void updateMediaSession(final String what) { int playState = mIsSupposedToBePlaying ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED; if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSession.setPlaybackState(new PlaybackState.Builder().setState(playState, position(), 1.0f) .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS) .build());/* w ww. j a v a 2s . co m*/ } } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { //Bitmap albumArt = ImageLoader.getInstance().loadImageSync(CommonUtils.getAlbumArtUri(getAlbumId()).toString()); Bitmap albumArt = null; if (albumArt != null) { Bitmap.Config config = albumArt.getConfig(); if (config == null) { config = Bitmap.Config.ARGB_8888; } albumArt = albumArt.copy(config, false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSession.setMetadata( new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_ARTIST, getArtistName()) .putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName()) .putString(MediaMetadata.METADATA_KEY_ALBUM, getAlbumName()) .putString(MediaMetadata.METADATA_KEY_TITLE, getTrackName()) .putLong(MediaMetadata.METADATA_KEY_DURATION, duration()) .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, getQueuePosition() + 1) .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, getQueue().length) .putString(MediaMetadata.METADATA_KEY_GENRE, getGenreName()) .putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, mShowAlbumArtOnLockscreen ? albumArt : null) .build()); mSession.setPlaybackState(new PlaybackState.Builder().setState(playState, position(), 1.0f) .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS) .build()); } } }