List of usage examples for android.support.v4.media MediaMetadataCompat METADATA_KEY_ALBUM_ART_URI
String METADATA_KEY_ALBUM_ART_URI
To view the source code for android.support.v4.media MediaMetadataCompat METADATA_KEY_ALBUM_ART_URI.
Click Source Link
From source file:dk.glutter.android.dansker.uamp.model.RemoteJSONSource.java
private MediaMetadataCompat 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;/*from w w w . j av a 2 s. co m*/ } if (!iconUrl.startsWith("http")) { iconUrl = "http://denstoredanske.dk/@api/deki/files/70689/=dannebrog.jpg"; } // 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. //noinspection ResourceType return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); }
From source file:com.example.hp.smartstor.CloudMusicManager.uamp.model.RemoteJSONSource.java
private MediaMetadataCompat buildFromJSON(JSONObject json, String basePath) throws JSONException { String title = json.getString(JSON_TITLE); String alb = json.getString(JSON_ALBUM); alb = alb.replace(" ", "%20"); String album = alb;/* www. j av a 2 s. c o m*/ Log.i("album after edit", alb); String artist = json.getString(JSON_ARTIST); String genre = json.getString(JSON_GENRE); String src = json.getString(JSON_SOURCE); src = src.replace(" ", "%20"); String source = src; 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; } 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. //noinspection ResourceType return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); }
From source file:com.murati.oszk.audiobook.model.RemoteJSONSource.java
protected MediaMetadataCompat buildFromJSON(JSONObject json, String basePath) throws JSONException { String writer = json.getString(JSON_WRITER); String ebook = json.getString(JSON_EBOOK_TITLE); String title = json.getString(JSON_TRACK_TITLE); int trackNumber = json.getInt(JSON_TRACK_NUMBER); String genre = json.getString(JSON_GENRE); String source = json.getString(JSON_SOURCE); String iconUrl = json.getString(JSON_IMAGE); int totalTrackCount = json.getInt(JSON_TOTAL_TRACK_COUNT); int duration = json.getInt(JSON_DURATION) * 1000; // ms LogHelper.d(TAG, "Loaded tracks: ", json); // Media is stored relative to JSON file if (!source.startsWith("http")) { source = basePath + source;//from w ww.jav a 2 s. c om } 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. //noinspection ResourceType // Skip faulty ones if (ebook == null || title == null || ebook.trim().length() * title.trim().length() == 0) { LogHelper.e(TAG, "Error processing JSON: " + json.toString()); return null; } // Fix writer if (writer == null || writer.trim().length() == 0) { if (title.contains(":")) { writer = title.split(":")[0]; } else { writer = "Ismeretlen szerz"; //TODO: resource } } //Fix title TODO: Strip from API ebook = ebook.replace(""", ""); ebook = ebook.replace("\"", ""); title = title.replace(""", "\""); return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, ebook) .putString(MediaMetadataCompat.METADATA_KEY_WRITER, writer) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); }
From source file:com.whitecloud.ron.musicplayer.model.MusicProvider.java
public ArrayList<Song> getTopTracks(String spotifyId) { try {//from www .j a v a 2 s .c o m if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; SpotifyApi api = new SpotifyApi(); SpotifyService spotify = api.getService(); Tracks tracks = spotify.getArtistTopTrack(spotifyId, "CA"); List<Track> trackList = tracks.tracks; if (trackList != null) { for (int j = 0; j < trackList.size(); j++) { Track track = trackList.get(j); MediaMetadataCompat item = new MediaMetadataCompat.Builder() .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, track.id) // .putString(CUSTOM_METADATA_TRACK_SOURCE, track.preview_url) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, track.album.name) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, track.artists.get(0).name) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, track.duration_ms) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, track.type) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, track.album.images.get(0).url) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, track.name) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, track.track_number) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, trackList.size()).build(); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); mMusicSourceList.put(musicId, track.preview_url); mSongs.add(new Song(track.preview_url, track.name, track.album.name, track.album.images.get(0).url, track.album.images.get(1).url)); } buildListsByGenre(); } mCurrentState = State.INITIALIZED; } } catch (RetrofitError e) { LogHelper.e(TAG, e, "Could not retrieve music list"); } finally { if (mCurrentState != State.INITIALIZED) { // Something bad happened, so we reset state to NON_INITIALIZED to allow // retries (eg if the network connection is temporary unavailable) mCurrentState = State.NON_INITIALIZED; } return (ArrayList) mSongs; } }
From source file:com.scooter1556.sms.android.utils.MediaUtils.java
public static MediaMetadataCompat getMediaMetadataCompatFromMediaElement(MediaElement mediaElement) { if (mediaElement == null) { return null; }// w w w. j av a 2s . c om // Update session metadata MediaMetadataCompat.Builder metadata = new MediaMetadataCompat.Builder(); metadata.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, mediaElement.getID().toString()); if (mediaElement.getArtist() != null) { metadata.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, mediaElement.getArtist()); metadata.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, mediaElement.getArtist()); } if (mediaElement.getAlbum() != null) { metadata.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, mediaElement.getAlbum()); metadata.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, mediaElement.getAlbum()); } if (mediaElement.getTitle() != null) { metadata.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mediaElement.getTitle()); metadata.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mediaElement.getTitle()); } if (mediaElement.getDuration() != null) { metadata.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, Double.valueOf(mediaElement.getDuration() * 1000.0).longValue()); } if (mediaElement.getYear() != null) { metadata.putLong(MediaMetadataCompat.METADATA_KEY_YEAR, mediaElement.getYear()); } if (mediaElement.getGenre() != null) { metadata.putString(MediaMetadataCompat.METADATA_KEY_GENRE, mediaElement.getGenre()); } if (mediaElement.getTrackNumber() != null) { metadata.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, mediaElement.getTrackNumber()); } if (mediaElement.getDiscNumber() != null) { metadata.putLong(MediaMetadataCompat.METADATA_KEY_DISC_NUMBER, mediaElement.getDiscNumber()); } if (mediaElement.getAlbumArtist() != null) { metadata.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, mediaElement.getAlbumArtist()); } if (RESTService.getInstance().getAddress() != null) { metadata.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, RESTService.getInstance().getAddress() + "/image/" + mediaElement.getID() + "/cover"); metadata.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, RESTService.getInstance().getAddress() + "/image/" + mediaElement.getID() + "/cover"); metadata.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, RESTService.getInstance().getAddress() + "/image/" + mediaElement.getID() + "/fanart"); } return metadata.build(); }
From source file:com.allthatseries.RNAudioPlayer.Playback.java
public void playFromUri(Uri uri, Bundle bundle) { mPlayOnFocusGain = true;/* w w w . ja v a 2 s . co m*/ tryToGetAudioFocus(); registerAudioNoisyReceiver(); mState = PlaybackStateCompat.STATE_STOPPED; relaxResources(true); try { createMediaPlayerIfNeeded(); mState = PlaybackStateCompat.STATE_BUFFERING; mCurrentPosition = 0; mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setDataSource(uri.toString()); // Starts preparing the media player in the background. When // it's done, it will call our OnPreparedListener (that is, // the onPrepared() method on this class, since we set the // listener to 'this'). Until the media player is prepared, // we *cannot* call start() on it! mMediaPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a // Wifi lock, which prevents the Wifi radio from going to // sleep while the song is playing. mWifiLock.acquire(); if (mCallback != null) { mCallback.onPlaybackStateChanged(mState); MediaMetadataCompat.Builder metaBuilder = new MediaMetadataCompat.Builder(); metaBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, bundle.getString(MediaMetadataCompat.METADATA_KEY_ARTIST)); metaBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, bundle.getString(MediaMetadataCompat.METADATA_KEY_TITLE)); metaBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, bundle.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)); mCallback.onMediaMetadataChanged(metaBuilder.build()); } } catch (IOException ex) { Log.e(TAG, ex + "Exception playing song"); if (mCallback != null) { mCallback.onError(ex.getMessage()); } } }
From source file:com.classiqo.nativeandroid_32bitz.playback.CastPlayback.java
private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) { MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK); mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.getDescription().getTitle() == null ? "" : track.getDescription().getTitle().toString()); mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle() == null ? "" : track.getDescription().getSubtitle().toString()); mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST)); mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM)); WebImage image = new WebImage(new Uri.Builder() .encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build()); mediaMetadata.addImage(image);//from w w w. jav a 2 s. c om mediaMetadata.addImage(image); //noinspection ResourceType return new MediaInfo.Builder(track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE)) .setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setMetadata(mediaMetadata).setCustomData(customData).build(); }
From source file:com.example.android.AudioArchive.model.RemoteJSONSource.java
private MediaMetadataCompat buildFromRSS(RSSItem rssItem, String genre) { String title = rssItem.getTitle(); String album = rssItem.categories.get(0).toString(); String artist = ""; if (rssItem.getDescription().contains("by")) { StringBuffer stringBuffer = new StringBuffer(rssItem.getDescription()); artist = stringBuffer.substring(stringBuffer.indexOf("by")); } else {// w w w .j a v a 2 s . c om artist = "Unknown"; } String source = rssItem.getEnclosures().get(0).getLink(); String iconUrl = "https://archive.org/services/get-item-image.php?identifier=afewmoreverses_1606_librivox&mediatype=audio&collection=librivoxaudio"; String html = rssItem.getDescription(); String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>"; Pattern p = Pattern.compile(imgRegex); Matcher m = p.matcher(html); if (m.find()) { iconUrl = m.group(1); } // 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. //noinspection ResourceType return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, source) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) // .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, title) .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, title) // .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .build(); }
From source file:com.livemasjid.livemasjidandroid.model.RemoteJSONSource.java
private MediaMetadataCompat buildFromJSON(JSONObject json, String basePath, int totalTracks, int trackNo, ArrayList<String> live) throws JSONException { try {/*from ww w . j a v a 2 s . c o m*/ String title = json.getString(JSON_STREAMNAME); String album = json.getString(JSON_STREAMNAME); String artist = json.getString(JSON_STREAMDESC); String genre = json.getString(JSON_GENRE).replaceAll("/", "-"); String listenURL = json.getString(JSON_STREAMURL); String id = json.getString(JSON_MOUNTNAME); String iconUrl = "http://livemasjid.com/images/MasjidLogo.png";//json.getString(JSON_IMAGE); if (genre.contains("Aalim")) { iconUrl = "http://livemasjid.com/images/AalimLogo.png"; } else if (genre.contains("Institution")) { iconUrl = "http://livemasjid.com/images/InstitutionLogo.png"; } int trackNumber = trackNo;//json.getInt(JSON_TRACK_NUMBER); int totalTrackCount = totalTracks;//json.getInt(JSON_TOTAL_TRACK_COUNT); int duration = 10000000;//json.getInt(JSON_DURATION) * 1000; // ms LogHelper.d(TAG, "Found music track: ", json); LogHelper.d(TAG, id); // Media is stored relative to JSON file if (!listenURL.startsWith("http")) { listenURL = "http://" + listenURL; } if (!live.contains(id)) { genre = "Offline"; title = "Last recording: " + title; listenURL = listenURL.replace(":8000", "/download/mp3") + "/latest.mp3"; //listenURL = listenURL.replace(":8000/","/download/mp3/dir2cast.php?dir="); } //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 listenURL. In a real world app, this could come from the server. //String id = String.valueOf(listenURL.hashCode()); // Adding the music listenURL 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. //noinspection ResourceType return new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, listenURL) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount).build(); } catch (JSONException e) { LogHelper.e(TAG, e, "Could not retrieve required track info"); return null; } }
From source file:com.torrenttunes.android.CastPlayback.java
/** * Helper method to convert a {@link MediaMetadataCompat} to a * {@link com.google.android.gms.cast.MediaInfo} used for sending media to the receiver app. * * @param track {@link com.google.android.gms.cast.MediaMetadata} * @param customData custom data specifies the local mediaId used by the player. * @return mediaInfo {@link com.google.android.gms.cast.MediaInfo} */// ww w. ja v a 2s .c o m private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) { MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK); mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.getDescription().getTitle().toString()); mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle().toString()); mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST)); mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM)); WebImage image = new WebImage(new Uri.Builder() .encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build()); // First image is used by the receiver for showing the audio album art. mediaMetadata.addImage(image); // Second image is used by Cast Companion Library on the full screen activity that is shown // when the cast dialog is clicked. mediaMetadata.addImage(image); return new MediaInfo.Builder(track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE)) .setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setMetadata(mediaMetadata).setCustomData(customData).build(); }