Example usage for android.media MediaMetadata METADATA_KEY_GENRE

List of usage examples for android.media MediaMetadata METADATA_KEY_GENRE

Introduction

In this page you can find the example usage for android.media MediaMetadata METADATA_KEY_GENRE.

Prototype

String METADATA_KEY_GENRE

To view the source code for android.media MediaMetadata METADATA_KEY_GENRE.

Click Source Link

Document

The genre of the media.

Usage

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   w  w w.  j  a  va2s . c  o  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;/*w  w  w .j  av a 2 s.c  o 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

private synchronized void buildListsByGenre() {
    ConcurrentMap<String, List<MediaMetadata>> newMusicListByGenre = new ConcurrentHashMap<>();

    for (MutableMediaMetadata m : mMusicListById.values()) {
        String genre = m.metadata.getString(MediaMetadata.METADATA_KEY_GENRE);
        List<MediaMetadata> list = newMusicListByGenre.get(genre);
        if (list == null) {
            list = new ArrayList<>();
            newMusicListByGenre.put(genre, list);
        }//from   w w w. j av a2s .  c o m
        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;
}

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  2s  . 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: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());/*from  w w  w  .  j a va 2 s .c  o  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());
        }
    }
}