List of usage examples for android.support.v4.media MediaMetadataCompat getString
public String getString(@TextKey String key)
From source file:com.phearom.um.model.MyMusicProvider.java
public void retrieveMedia(Iterator<MediaMetadataCompat> tracks, Callback callback) { LogHelper.d(TAG, "retrieveMediaAsync called"); if (mCurrentState == State.INITIALIZED) { if (callback != null) { callback.onMusicCatalogReady(true); }// w w w . j a va 2 s . c o m return; } try { if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; while (tracks.hasNext()) { MediaMetadataCompat item = tracks.next(); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); mCurrentState = State.INITIALIZED; } } finally { if (mCurrentState != State.INITIALIZED) { mCurrentState = State.NON_INITIALIZED; } } if (callback != null) callback.onMusicCatalogReady(mCurrentState == State.INITIALIZED); }
From source file:com.appdevper.mediaplayer.model.MusicProvider.java
public synchronized void retrieveMedia(ArrayList<ContentItem> contentItems) { //if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; for (ContentItem contentItem : contentItems) { MediaMetadataCompat item = buildFromContent(contentItem); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); Log.i("retrieveMedia", "musicId: " + musicId); if (!mMusicListById.containsKey(musicId)) mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); }//from w w w. j av a 2s . c om buildListsByGenre(); mCurrentState = State.INITIALIZED; // } }
From source file:com.classiqo.nativeandroid_32bitz.model.MusicProvider.java
private synchronized void retrieveMedia() { try {/*from w w w. ja v a 2s. c om*/ if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; Iterator<MediaMetadataCompat> tracks = mSource.iterator(); while (tracks.hasNext()) { MediaMetadataCompat item = tracks.next(); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); mCurrentState = State.INITIALIZED; } } finally { if (mCurrentState != State.INITIALIZED) { mCurrentState = State.NON_INITIALIZED; } } }
From source file:org.opensilk.music.ui3.main.FooterScreenPresenter.java
void subscribeBroadcasts() { if (isSubscribed(broadcastSubscriptions)) { return;/*www .j a va 2s.c om*/ } Subscription s = playbackController.subscribePlayStateChanges(new Action1<PlaybackStateCompat>() { @Override public void call(PlaybackStateCompat playbackState) { final int state = playbackState.getState(); if (state == STATE_BUFFERING || state == STATE_CONNECTING) { setProgress(-1); } else { long position = playbackState.getPosition(); long duration = playbackState.getBufferedPosition(); if (position < 0 || duration <= 0) { setProgress(1000); } else { setProgress((int) (1000 * position / duration)); } Timber.v("Position discrepancy = %d", lastPosition - position); lastPosition = position; lastDuration = duration; lastPosSynced = true; subscribeProgress(MainPresenter.isPlaying(playbackState)); } } }); Subscription s2 = playbackController.subscribeMetaChanges(new Action1<MediaMetadataCompat>() { @Override public void call(MediaMetadataCompat mediaMetadata) { setTrackName(mediaMetadata.getString(METADATA_KEY_TITLE)); setArtistName(mediaMetadata.getString(METADATA_KEY_ARTIST)); updateArtwork(mediaMetadata.getBitmap(METADATA_KEY_ALBUM_ART)); } }); broadcastSubscriptions = new CompositeSubscription(s, s2); }
From source file:com.bayapps.android.robophish.model.MusicProvider.java
private MediaBrowserCompat.MediaItem createBrowsableMediaItemForShow(MediaMetadataCompat show, Resources resources) {/*w w w . j av a 2 s. com*/ String showId = show.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); String venue = show.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE); String location = show.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE); String date = show.getString(MediaMetadataCompat.METADATA_KEY_DATE); MediaDescriptionCompat description = new MediaDescriptionCompat.Builder() .setMediaId(createMediaID(null, MEDIA_ID_TRACKS_BY_SHOW, showId)).setTitle(venue) .setSubtitle(resources.getString(R.string.browse_musics_by_genre_subtitle, date)) .setDescription(location).build(); return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE); }
From source file:com.pi.android.brainbeats.ui.PlaybackControlsFragment.java
private int getMusicID(MediaMetadataCompat metadata) { if (metadata == null) { return -1; }/* w w w . j a va2s. c om*/ String musicId = metadata.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); return Integer.parseInt(musicId); }
From source file:com.example.android.AudioArchive.model.MusicProvider.java
private synchronized void retrieveMedia() { try {//from ww w . j a v a2 s .c om if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; Iterator<MediaMetadataCompat> tracks = mSource.iterator(); while (tracks.hasNext()) { MediaMetadataCompat item = tracks.next(); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); mCurrentState = State.INITIALIZED; } } 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.hp.smartstor.CloudMusicManager.uamp.model.MusicProvider.java
private synchronized void retrieveMedia() { try {//from w w w.j a va 2s .c o m if (mCurrentState == State.NON_INITIALIZED) { mCurrentState = State.INITIALIZING; Iterator<MediaMetadataCompat> tracks = mSource.iterator(); while (tracks.hasNext()) { MediaMetadataCompat item = tracks.next(); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new com.example.hp.smartstor.CloudMusicManager.uamp.model.MutableMediaMetadata(musicId, item)); } buildListsByGenre(); mCurrentState = State.INITIALIZED; } } 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.supportv4.media.model.MusicProvider.java
private synchronized void retrieveMedia() { try {//from w w w.j a v a2 s . 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++) { MediaMetadataCompat item = buildFromJSON(tracks.getJSONObject(j), path); String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item)); } buildListsByGenre(); } mCurrentState = State.INITIALIZED; } } catch (JSONException e) { Log.e(TAG, "Could not retrieve music list", e); } 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.bayapps.android.robophish.model.MusicProvider.java
public synchronized void getChildrenAsync(final String mediaId, final Resources resources, final Callback callback) { final List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>(); if (!MediaIDHelper.isBrowseable(mediaId)) { callback.children(mediaItems);/*from www . j av a 2 s. co m*/ } else if (MEDIA_ID_ROOT.equals(mediaId)) { // Asynchronously load the years in a separate thread new AsyncTask<Void, Void, State>() { @Override protected State doInBackground(Void... params) { List<YearData> years = mSource.years(); //always refresh years so we get fresh show count if (!mYears.isEmpty() && (years.get(0).getShowCount() != mYears.get(0).getShowCount())) { mShowsInYearYear = new ConcurrentHashMap<>(); //clear cache if number of shows have changed } mYears = years; for (YearData year : mYears) { mediaItems.add( createBrowsableMediaItemForYear(year.getYear(), year.getShowCount(), resources)); } return null; } @Override protected void onPostExecute(State current) { if (callback != null) { callback.children(mediaItems); } } }.execute(); } else if (mediaId.startsWith(MEDIA_ID_SHOWS_BY_YEAR)) { // Asynchronously load the shows in a separate thread new AsyncTask<Void, Void, State>() { @Override protected State doInBackground(Void... params) { final String year = MediaIDHelper.getHierarchy(mediaId)[1]; LogHelper.w(TAG, "year: ", year); List<MediaMetadataCompat> shows = mShowsInYearYear.get(year); if (shows == null || shows.isEmpty()) { shows = Lists.newArrayList(mSource.showsInYear(year)); mShowsInYearYear.put(year, shows); } for (MediaMetadataCompat show : shows) { mediaItems.add(createBrowsableMediaItemForShow(show, resources)); } return null; } @Override protected void onPostExecute(State current) { if (callback != null) { callback.children(mediaItems); } } }.execute(); } else if (mediaId.startsWith(MEDIA_ID_TRACKS_BY_SHOW)) { // Asynchronously load the shows in a separate thread new AsyncTask<Void, Void, State>() { @Override protected State doInBackground(Void... params) { final String showId = MediaIDHelper.getHierarchy(mediaId)[1]; LogHelper.w(TAG, "showId: ", showId); List<MediaMetadataCompat> tracks = mTracksInShow.get(showId); if (tracks == null || tracks.isEmpty()) { tracks = Lists.newArrayList(mSource.tracksInShow(showId)); mTracksInShow.put(showId, tracks); } for (MediaMetadataCompat track : tracks) { String id = track.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID); mediaItems.add(createMediaItem(track)); mMusicListById.put(id, new MutableMediaMetadata(id, track)); } return null; } @Override protected void onPostExecute(State current) { if (callback != null) { callback.children(mediaItems); } } }.execute(); } else { LogHelper.w(TAG, "Skipping unmatched mediaId: ", mediaId); } }