List of usage examples for android.media MediaMetadata METADATA_KEY_TRACK_NUMBER
String METADATA_KEY_TRACK_NUMBER
To view the source code for android.media MediaMetadata METADATA_KEY_TRACK_NUMBER.
Click Source Link
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 av a 2 s . c o 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: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: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());/* www .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()); } } }