Example usage for android.support.v4.media MediaMetadataCompat METADATA_KEY_MEDIA_ID

List of usage examples for android.support.v4.media MediaMetadataCompat METADATA_KEY_MEDIA_ID

Introduction

In this page you can find the example usage for android.support.v4.media MediaMetadataCompat METADATA_KEY_MEDIA_ID.

Prototype

String METADATA_KEY_MEDIA_ID

To view the source code for android.support.v4.media MediaMetadataCompat METADATA_KEY_MEDIA_ID.

Click Source Link

Document

A String key for identifying the content.

Usage

From source file:com.classiqo.nativeandroid_32bitz.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
    String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(),
            MEDIA_ID_MUSICS_BY_GENRE, genre);
    MediaMetadataCompat copy = new MediaMetadataCompat.Builder(metadata)
            .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();

    return new MediaBrowserCompat.MediaItem(copy.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
}

From source file:com.torrenttunes.android.model.MusicProvider.java

@Deprecated
private synchronized void retrieveMedia2() {
    try {/*from w  w w.  ja  v a 2 s .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 = fetchJSONObjectFromUrl(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 MutableMediaMetadataCompat(musicId, item));
                }
                buildListsByArtist();
            }
            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.bayapps.android.robophish.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    // Since mediaMetadata fields are immutable, we need to create a copy, so we
    // can set a hierarchy-aware mediaID. We will need to know the media hierarchy
    // when we get a onPlayFromMusicID call, so we can create the proper queue based
    // on where the music was selected from (by artist, by genre, random, etc)
    String title = metadata.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID);

    String venue = metadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE);

    String showId = metadata.getString(MediaMetadataCompat.METADATA_KEY_COMPILATION);
    String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(),
            MEDIA_ID_TRACKS_BY_SHOW, showId);
    MediaMetadataCompat copy = new MediaMetadataCompat.Builder(metadata)
            .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID)
            .putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, venue).build();

    return new MediaBrowserCompat.MediaItem(copy.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);

}

From source file:com.murati.oszk.audiobook.model.MusicProvider.java

private synchronized void retrieveMedia() {
    try {//from w w  w. j  av a  2 s.  co m
        if (mCurrentState == State.NON_INITIALIZED) {
            mCurrentState = State.INITIALIZING;

            Iterator<MediaMetadataCompat> tracks = mSource.iterator();
            mEbookListByGenre = new ConcurrentHashMap<>();
            mEbookListByWriter = new ConcurrentHashMap<>();

            while (tracks.hasNext()) {
                MediaMetadataCompat item = tracks.next();
                String musicId = item.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID);
                MutableMediaMetadata m = new MutableMediaMetadata(musicId, item);

                mTrackListById.put(musicId, m);

                addMediaToCategory(m, MediaMetadataCompat.METADATA_KEY_GENRE, mEbookListByGenre);
                addMediaToCategory(m, MediaMetadataCompat.METADATA_KEY_WRITER, mEbookListByWriter);
            }

            Long startTime = System.currentTimeMillis();
            Log.d(TAG, "Build catalog started at " + startTime.toString());

            buildAlbumList();

            Long endTime = System.currentTimeMillis();
            Log.d(TAG, "Build catalog finished at " + endTime.toString());

            Log.d(TAG, "Build time was: " + Long.toString(endTime - startTime));
            mCurrentState = State.INITIALIZED;
        }
    } catch (Exception e) {
        LogHelper.e(e.getMessage());
    } finally {
        if (mCurrentState != State.INITIALIZED)
            mCurrentState = State.NON_INITIALIZED;
    }
}

From source file:org.copticchurchlibrary.arabicreader.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    // Since mediaMetadata fields are immutable, we need to create a copy, so we
    // can set a hierarchy-aware mediaID. We will need to know the media hierarchy
    // when we get a onPlayFromMusicID call, so we can create the proper queue based
    // on where the music was selected from (by artist, by genre, random, etc)
    String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
    String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(),
            MediaIDHelper.MEDIA_ID_MUSICS_BY_GENRE, genre);
    MediaMetadataCompat copy = new MediaMetadataCompat.Builder(metadata)
            .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();
    return new MediaBrowserCompat.MediaItem(copy.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);

}

From source file:com.example.android.AudioArchive.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    // Since mediaMetadata fields are immutable, we need to create a copy, so we
    // can set a hierarchy-aware mediaID. We will need to know the media hierarchy
    // when we get a onPlayFromMusicID call, so we can create the proper queue based
    // on where the music was selected from (by artist, by genre, random, etc)
    String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
    String hierarchyAwareMediaID = MediaIDHelper.createMediaID(metadata.getDescription().getMediaId(),
            MEDIA_ID_MUSICS_BY_GENRE, genre);
    MediaMetadataCompat copy = new MediaMetadataCompat.Builder(metadata)
            .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();
    return new MediaBrowserCompat.MediaItem(copy.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);

}

From source file:com.torrenttunes.android.model.MusicProvider.java

private MediaMetadataCompat buildFromJSON(JSONObject json, String basePath) throws JSONException {
    LogHelper.i(TAG, json);/*from   w w w.j  ava 2  s . c o m*/
    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);
    long totalTrackCount = json.getLong(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;
    }
    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 MediaMetadataCompat (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 MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, id)
            //                .putString(CUSTOM_METADATA_TRACK_SOURCE, source)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album)
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
            .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration)
            .putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre)
            .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, iconUrl)
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
            .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, trackNumber)
            // Note: With MediaMetadataCompat we seem to crash when setting the total track count.
            // .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, totalTrackCount * 1L)

            .build();
}

From source file:com.example.lzhang.stockchartt.media.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createMediaItem(MediaMetadataCompat metadata) {
    // Since mediaMetadata fields are immutable, we need to create a copy, so we
    // can set a hierarchy-aware mediaID. We will need to know the media hierarchy
    // when we get a onPlayFromMusicID call, so we can create the proper queue based
    // on where the music was selected from (by artist, by genre, random, etc)
    String genre = metadata.getString(MediaMetadataCompat.METADATA_KEY_GENRE);
    String hierarchyAwareMediaID = createMediaID(metadata.getDescription().getMediaId(),
            MEDIA_ID_MUSICS_BY_GENRE, genre);
    MediaMetadataCompat copy = new MediaMetadataCompat.Builder(metadata)
            .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();
    return new MediaBrowserCompat.MediaItem(copy.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);

}

From source file:com.example.android.mediabrowserservice.MusicService.java

/**
 * Actual implementation of onLoadChildren that assumes that MusicProvider is already
 * initialized./*from  w  ww  .  j  a  va2 s . c  om*/
 */
private void loadChildrenImpl(final String parentMediaId,
        final Result<List<MediaBrowserCompat.MediaItem>> result) {
    LogHelper.d(TAG, "OnLoadChildren: parentMediaId=", parentMediaId);

    List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();

    if (MEDIA_ID_ROOT.equals(parentMediaId)) {
        LogHelper.d(TAG, "OnLoadChildren.ROOT");
        mediaItems.add(new MediaBrowserCompat.MediaItem(
                new MediaDescriptionCompat.Builder().setMediaId(MEDIA_ID_MUSICS_BY_GENRE)
                        .setTitle(getString(R.string.browse_genres))
                        .setIconUri(Uri.parse("android.resource://"
                                + "com.example.android.mediabrowserservice/drawable/ic_by_genre"))
                        .setSubtitle(getString(R.string.browse_genre_subtitle)).build(),
                MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));

    } else if (MEDIA_ID_MUSICS_BY_GENRE.equals(parentMediaId)) {
        LogHelper.d(TAG, "OnLoadChildren.GENRES");
        for (String genre : mMusicProvider.getGenres()) {
            MediaBrowserCompat.MediaItem item = new MediaBrowserCompat.MediaItem(
                    new MediaDescriptionCompat.Builder()
                            .setMediaId(createBrowseCategoryMediaID(MEDIA_ID_MUSICS_BY_GENRE, genre))
                            .setTitle(genre)
                            .setSubtitle(getString(R.string.browse_musics_by_genre_subtitle, genre)).build(),
                    MediaBrowserCompat.MediaItem.FLAG_BROWSABLE);
            mediaItems.add(item);
        }

    } else if (parentMediaId.startsWith(MEDIA_ID_MUSICS_BY_GENRE)) {
        String genre = MediaIDHelper.getHierarchy(parentMediaId)[1];
        LogHelper.d(TAG, "OnLoadChildren.SONGS_BY_GENRE  genre=", genre);
        for (MediaMetadataCompat track : mMusicProvider.getMusicsByGenre(genre)) {
            // Since mediaMetadata fields are immutable, we need to create a copy, so we
            // can set a hierarchy-aware mediaID. We will need to know the media hierarchy
            // when we get a onPlayFromMusicID call, so we can create the proper queue based
            // on where the music was selected from (by artist, by genre, random, etc)
            String hierarchyAwareMediaID = MediaIDHelper.createMediaID(track.getDescription().getMediaId(),
                    MEDIA_ID_MUSICS_BY_GENRE, genre);
            MediaMetadataCompat trackCopy = new MediaMetadataCompat.Builder(track)
                    .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();
            MediaBrowserCompat.MediaItem bItem = new MediaBrowserCompat.MediaItem(trackCopy.getDescription(),
                    MediaBrowserCompat.MediaItem.FLAG_PLAYABLE);
            mediaItems.add(bItem);
        }
    } else {
        LogHelper.w(TAG, "Skipping unmatched parentMediaId: ", parentMediaId);
    }
    LogHelper.d(TAG, "OnLoadChildren sending ", mediaItems.size(), " results for ", parentMediaId);
    result.sendResult(mediaItems);
}

From source file:com.example.android.supportv4.media.MediaBrowserServiceSupport.java

/**
 * Actual implementation of onLoadChildren that assumes that MusicProvider is already
 * initialized./*from w w  w .  j  a  v  a 2  s .  co  m*/
 */
private void loadChildrenImpl(final String parentMediaId, final Result<List<MediaItem>> result,
        final Bundle options) {
    Log.d(TAG, "OnLoadChildren: parentMediaId=" + parentMediaId + ", options=" + options);

    int page = -1;
    int pageSize = -1;

    if (options != null && (options.containsKey(MediaBrowserCompat.EXTRA_PAGE)
            || options.containsKey(MediaBrowserCompat.EXTRA_PAGE_SIZE))) {
        page = options.getInt(MediaBrowserCompat.EXTRA_PAGE, -1);
        pageSize = options.getInt(MediaBrowserCompat.EXTRA_PAGE_SIZE, -1);

        if (page < 0 || pageSize < 1) {
            result.sendResult(new ArrayList<MediaItem>());
            return;
        }
    }

    int fromIndex = page == -1 ? 0 : page * pageSize;
    int toIndex = 0;

    List<MediaItem> mediaItems = new ArrayList<>();

    if (MEDIA_ID_ROOT.equals(parentMediaId)) {
        Log.d(TAG, "OnLoadChildren.ROOT");
        if (page <= 0) {
            mediaItems.add(new MediaItem(
                    new MediaDescriptionCompat.Builder().setMediaId(MEDIA_ID_MUSICS_BY_GENRE)
                            .setTitle(getString(R.string.browse_genres))
                            .setIconUri(Uri.parse("android.resource://"
                                    + "com.example.android.supportv4.media/drawable/ic_by_genre"))
                            .setSubtitle(getString(R.string.browse_genre_subtitle)).build(),
                    MediaItem.FLAG_BROWSABLE));
        }

    } else if (MEDIA_ID_MUSICS_BY_GENRE.equals(parentMediaId)) {
        Log.d(TAG, "OnLoadChildren.GENRES");

        List<String> genres = mMusicProvider.getGenres();
        toIndex = page == -1 ? genres.size() : Math.min(fromIndex + pageSize, genres.size());

        for (int i = fromIndex; i < toIndex; i++) {
            String genre = genres.get(i);
            MediaItem item = new MediaItem(new MediaDescriptionCompat.Builder()
                    .setMediaId(createBrowseCategoryMediaID(MEDIA_ID_MUSICS_BY_GENRE, genre)).setTitle(genre)
                    .setSubtitle(getString(R.string.browse_musics_by_genre_subtitle, genre)).build(),
                    MediaItem.FLAG_BROWSABLE);
            mediaItems.add(item);
        }

    } else if (parentMediaId.startsWith(MEDIA_ID_MUSICS_BY_GENRE)) {
        String genre = MediaIDHelper.getHierarchy(parentMediaId)[1];
        Log.d(TAG, "OnLoadChildren.SONGS_BY_GENRE  genre=" + genre);

        List<MediaMetadataCompat> tracks = mMusicProvider.getMusicsByGenre(genre);
        toIndex = page == -1 ? tracks.size() : Math.min(fromIndex + pageSize, tracks.size());

        for (int i = fromIndex; i < toIndex; i++) {
            MediaMetadataCompat track = tracks.get(i);

            // Since mediaMetadata fields are immutable, we need to create a copy, so we
            // can set a hierarchy-aware mediaID. We will need to know the media hierarchy
            // when we get a onPlayFromMusicID call, so we can create the proper queue based
            // on where the music was selected from (by artist, by genre, random, etc)
            String hierarchyAwareMediaID = MediaIDHelper.createMediaID(track.getDescription().getMediaId(),
                    MEDIA_ID_MUSICS_BY_GENRE, genre);
            MediaMetadataCompat trackCopy = new MediaMetadataCompat.Builder(track)
                    .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, hierarchyAwareMediaID).build();
            MediaItem bItem = new MediaItem(trackCopy.getDescription(), MediaItem.FLAG_PLAYABLE);
            mediaItems.add(bItem);
        }
    } else {
        Log.w(TAG, "Skipping unmatched parentMediaId: " + parentMediaId);
    }
    Log.d(TAG, "OnLoadChildren sending " + mediaItems.size() + " results for " + parentMediaId);
    result.sendResult(mediaItems);
}