List of usage examples for android.media MediaMetadata METADATA_KEY_MEDIA_ID
String METADATA_KEY_MEDIA_ID
To view the source code for android.media MediaMetadata METADATA_KEY_MEDIA_ID.
Click Source Link
From source file:com.example.android.mediabrowserservice.model.MusicProvider.java
private synchronized void retrieveMedia() { try {// www .j a va2s . c o m if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; int slashPos = CATALOG_URL.lastIndexOf('/'); String path = CATALOG_URL.substring(0, slashPos + 1); JSONObject jsonObj = fetchJSONFromUrl(CATALOG_URL); if (jsonObj == null) { return; } JSONArray tracks = jsonObj.getJSONArray(JSON_MUSIC); if (tracks != null) { for (int j = 0; j < tracks.length(); j++) { MediaMetadata item = buildFromJSON(tracks.getJSONObject(j), path); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); } mCurrentState = State.INITIALIZED; } } catch (JSONException 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; } } }
From source file:robert843.o2.pl.player.model.MusicProvider.java
private synchronized void retrieveMedia() { PlaylistDB pdb = new PlaylistDB(this.mContext); ConcurrentMap<String, List<MediaMetadata>> newMusicListByGenre = new ConcurrentHashMap<>(); try {// w w w .j ava2 s . co m if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; for (String playlist : pdb.getListPlaylist()) { for (String id : pdb.getTracks(playlist)) { List<MediaMetadata> list = newMusicListByGenre.get(playlist); if (list == null) { list = new ArrayList<>(); newMusicListByGenre.put(playlist, list); } MediaMetadata item = buildFromJSON(id); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); list.add(item); } } mMusicListByGenre = newMusicListByGenre; /*int slashPos = CATALOG_URL.lastIndexOf('/'); String path = CATALOG_URL.substring(0, slashPos + 1); JSONObject jsonObj = fetchJSONFromUrl(CATALOG_URL); if (jsonObj == null) { return; } JSONArray tracks = jsonObj.getJSONArray(JSON_MUSIC); if (tracks != null) { for (int j = 0; j < tracks.length(); j++) { MediaMetadata item = buildFromJSON(tracks.getJSONObject(j), path); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); }*/ mCurrentState = State.INITIALIZED; } } catch (JSONException e) { LogHelper.e(TAG, e, "Could not retrieve music list"); } catch (ParserConfigurationException e) { LogHelper.e(TAG, e, "Could not retrieve music list"); } catch (IOException e) { // e.printStackTrace(); } 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; } } }
From source file:de.rwth_aachen.comsys.audiosync.model.MusicProvider.java
private synchronized void retrieveMedia() { try {/*w w w . j a va 2s. com*/ if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; int slashPos = CATALOG_URL.lastIndexOf('/'); String path = CATALOG_URL.substring(0, slashPos + 1); JSONObject jsonObj = fetchJSONFromUrl(CATALOG_URL); if (jsonObj == null) { buildListsByGenre();// TODO only for testing mCurrentState = State.INITIALIZED; return; } JSONArray tracks = jsonObj.getJSONArray(JSON_MUSIC); if (tracks != null) { for (int j = 0; j < tracks.length(); j++) { MediaMetadata item = buildFromJSON(tracks.getJSONObject(j), path); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); } mCurrentState = State.INITIALIZED; } } catch (JSONException 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; } } }
From source file:com.chinaftw.music.model.MusicProvider.java
private synchronized void retrieveMedia() { try {/*from www . j av a 2 s. c o m*/ if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; JSONObject jsonObj = MusicAPI.getPlaylistDetails("60198"); if (jsonObj == null) { return; } JSONArray tracks = jsonObj.getJSONArray(JSON_TRACKS); if (tracks != null) { for (int j = 0; j < 20; j++) { MediaMetadata item = buildFromJSON(tracks.getJSONObject(j)); String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); } mCurrentState = State.INITIALIZED; } } catch (JSONException e) { e.printStackTrace(); } 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; } } }
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;/*from w w w .j a v a 2 s . co m*/ } 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: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: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();// ww w . ja v a 2 s .c o m 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.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//w w w .ja v a 2 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// w ww.ja v a 2s. com public void onResourceReady(Bitmap bitmap, GlideAnimation anim) { metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap); mSession.setMetadata(metadataBuilder.build()); } }); }