List of usage examples for android.media MediaMetadata getString
public String getString(@TextKey String key)
From source file:com.orangesoft.jook.CastPlayback.java
/** * Helper method to convert a {@link android.media.MediaMetadata} 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} *//*from w w w.java 2 s . c om*/ private static MediaInfo toCastMediaMetadata(MediaMetadata track, JSONObject customData) { com.google.android.gms.cast.MediaMetadata metadata = new com.google.android.gms.cast.MediaMetadata( com.google.android.gms.cast.MediaMetadata.MEDIA_TYPE_MUSIC_TRACK); metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_TITLE, track.getDescription().getTitle() == null ? "" : track.getDescription().getTitle().toString()); metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle() == null ? "" : track.getDescription().getSubtitle().toString()); metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_ARTIST, track.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST)); metadata.putString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_TITLE, track.getString(MediaMetadata.METADATA_KEY_ALBUM)); WebImage image = new WebImage( new Uri.Builder().encodedPath(track.getString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI)).build()); // First image is used by the receiver for showing the audio album art. metadata.addImage(image); // Second image is used by Cast Companion Library on the full screen activity that is shown // when the cast dialog is clicked. metadata.addImage(image); return new MediaInfo.Builder(track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE)) .setContentType(MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setMetadata(metadata).setCustomData(customData).build(); }
From source file:com.chinaftw.music.model.MusicProvider.java
private synchronized void retrieveMedia() { try {//from w w w .j av a2 s . c om 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 synchronized void retrieveMedia() { try {/*from w w w . jav a 2s.c om*/ 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 {/* www. j a v a2 s . com*/ 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 {/*from w w w . j a va 2 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) { 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.example.android.mediabrowserservice.model.MusicProvider.java
public synchronized void updateMusic(String musicId, MediaMetadata metadata) { MutableMediaMetadata track = mMusicListById.get(musicId); if (track == null) { return;/*from www. ja v a2s.co m*/ } String oldGenre = track.metadata.getString(MediaMetadata.METADATA_KEY_GENRE); String newGenre = metadata.getString(MediaMetadata.METADATA_KEY_GENRE); track.metadata = metadata; // if genre has changed, we need to rebuild the list by genre if (!oldGenre.equals(newGenre)) { buildListsByGenre(); } }
From source file:com.chinaftw.music.model.MusicProvider.java
public synchronized void updateMusic(String musicId, MediaMetadata metadata) { MutableMediaMetadata track = mMusicListById.get(musicId); if (track == null) { return;//from w ww .j a v a2s . co m } String oldGenre = track.metadata.getString(MediaMetadata.METADATA_KEY_GENRE); String newGenre = metadata.getString(MediaMetadata.METADATA_KEY_GENRE); track.metadata = metadata; // if genre has changed, we need to rebuild the list by genre if (!oldGenre.equals(newGenre)) { buildListsByGenre(); } }
From source file:robert843.o2.pl.player.LocalPlayback.java
@Override public void play(QueueItem item) { mPlayOnFocusGain = true;//from www. j a v a 2s . c o m tryToGetAudioFocus(); registerAudioNoisyReceiver(); String mediaId = item.getDescription().getMediaId(); boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId); if (mediaHasChanged) { mCurrentPosition = 0; mCurrentMediaId = mediaId; } if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) { configMediaPlayerState(); } else { mState = PlaybackState.STATE_STOPPED; relaxResources(false); // release everything except MediaPlayer final MediaMetadata track = mMusicProvider .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId())); String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE); // Asynchronously load the music catalog in a separate thread new AsyncTask<Void, Void, MovieParser>() { @Override protected MovieParser doInBackground(Void... params) { MovieParser parser = new MovieParser(track.getString("id")); try { parser.parse(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return parser; } @Override protected void onPostExecute(MovieParser current) { createMediaPlayerIfNeeded(); mState = PlaybackState.STATE_BUFFERING; mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mMediaPlayer.setDataSource(current.getUrl()); } catch (IOException e) { e.printStackTrace(); } // 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.onPlaybackStatusChanged(mState); } } }.execute(); } }
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)); }