Example usage for android.media MediaMetadata METADATA_KEY_TITLE

List of usage examples for android.media MediaMetadata METADATA_KEY_TITLE

Introduction

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

Prototype

String METADATA_KEY_TITLE

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

Click Source Link

Document

The title of the media.

Usage

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

/**
 * Very basic implementation of a search that filter music tracks which title containing
 * the given query./*www  . ja  v  a 2s .  co  m*/
 *
 */
public Iterable<MediaMetadata> searchMusic(String titleQuery) {
    if (mCurrentState != State.INITIALIZED) {
        return Collections.emptyList();
    }
    ArrayList<MediaMetadata> result = new ArrayList<>();
    titleQuery = titleQuery.toLowerCase();
    for (MutableMediaMetadata track : mMusicListById.values()) {
        if (track.metadata.getString(MediaMetadata.METADATA_KEY_TITLE).toLowerCase().contains(titleQuery)) {
            result.add(track.metadata);
        }
    }
    return result;
}

From source file:com.chinaftw.music.model.MusicProvider.java

/**
 * Very basic implementation of a search that filter music tracks with title containing
 * the given query.//  ww w .  ja  v a2 s . co  m
 *
 */
public Iterable<MediaMetadata> searchMusicBySongTitle(String query) {
    return searchMusic(MediaMetadata.METADATA_KEY_TITLE, query);
}

From source file:hkapps.playmxtv.Activities.PlaybackOverlayActivity.java

private void updateMetadata(final Ficha movie) {
    final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();

    String title = movie.getTitle().replace("_", " -");

    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, movie.getSinopsis());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, movie.getPoster());

    // And at minimum the title and artist for legacy support
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, title);
    //metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, movie.);

    Glide.with(this).load(Uri.parse(movie.getPoster())).asBitmap().into(new SimpleTarget<Bitmap>(500, 500) {
        @Override/*from   ww  w . j  ava2 s  .  c  o  m*/
        public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
            metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
            mSession.setMetadata(metadataBuilder.build());
        }
    });
}

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 ww .ja  va 2 s.  c  om
    }
    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:org.opensilk.video.playback.PlaybackService.java

void updateMetadata() {
    assertCreated();//from  w  w  w.  j a  v a  2 s  .  co m
    final Media media = mMediaPlayer.getMedia();
    final MediaBrowser.MediaItem mediaItem = mDbClient.getMedia(media.getUri());

    final MediaMetadata.Builder b = new MediaMetadata.Builder();
    CharSequence title;
    Uri artworkUri = null;
    long duration;
    if (mediaItem != null) {
        MediaDescription description = mediaItem.getDescription();
        title = description.getTitle();
        b.putText(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
        b.putText(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, description.getSubtitle());
        if (description.getIconUri() != null) {
            b.putText(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, description.getIconUri().toString());
            artworkUri = description.getIconUri();
        }
        MediaMetaExtras metaExtras = MediaMetaExtras.from(description);
        b.putText(MediaMetadata.METADATA_KEY_TITLE, metaExtras.getMediaTitle());
        duration = metaExtras.getDuration();
    } else {
        title = media.getMeta(Media.Meta.Title);
        b.putText(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
        String artworkUrl = media.getMeta(Media.Meta.ArtworkURL);
        if (!StringUtils.isEmpty(artworkUrl)) {
            b.putText(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, artworkUrl);
            artworkUri = Uri.parse(artworkUrl);
        }
        duration = mMediaPlayer.getLength();
    }
    b.putLong(MediaMetadata.METADATA_KEY_DURATION, duration);
    if (artworkUri != null) {
        RequestOptions options = new RequestOptions().fitCenter(mContext);
        FutureTarget<Bitmap> futureTarget = Glide.with(mContext).asBitmap().apply(options).load(artworkUri)
                .submit();
        try {
            Bitmap bitmap = futureTarget.get(5000, TimeUnit.MILLISECONDS);
            b.putBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON, bitmap);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            //pass
        }
    }
    mMediaSession.setMetadata(b.build());
    mMediaSession.setSessionActivity(makeActivityIntent(mediaItem));
}

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:robert843.o2.pl.player.model.MusicProvider.java

private MediaMetadata buildFromJSON(String ytId)
        throws JSONException, ParserConfigurationException, IOException {
    String title = "";
    String artist = "";
    String source = "";
    String iconUrl = "";
    String site = "yt";
    int duration = 0; // ms

    LogHelper.d(TAG, "Found music track: ", ytId);

    // Media is stored relative to JSON file
    if (site.contains("yt")) {
        MovieParser parser = new MovieParser(ytId);
        parser.parse();//from   w w w .  j  a  v  a  2  s .  com
        source = "" + parser.getUrl();
        duration = parser.getLength() * 1000;
        iconUrl = parser.getAlbumUrl();
        System.out.println(iconUrl);
        title = parser.getTitle();
        artist = parser.getChanelName();
    }

    // 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_ARTIST, artist).putString("id", ytId)
            .putLong(MediaMetadata.METADATA_KEY_DURATION, duration)
            .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, iconUrl)
            .putString(MediaMetadata.METADATA_KEY_TITLE, title).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:uk.org.ngo.squeezer.service.SqueezeService.java

/**
 * Manages the state of any ongoing notification based on the player and connection state.
 */// w  w w  .j  a  va 2  s . c  o  m
private void updateOngoingNotification() {
    Player activePlayer = this.mActivePlayer.get();
    PlayerState activePlayerState = getActivePlayerState();

    // Update scrobble state, if either we're currently scrobbling, or we
    // were (to catch the case where we started scrobbling a song, and the
    // user went in to settings to disable scrobbling).
    if (scrobblingEnabled || scrobblingPreviouslyEnabled) {
        scrobblingPreviouslyEnabled = scrobblingEnabled;
        Scrobble.scrobbleFromPlayerState(this, activePlayerState);
    }

    // If there's no active player then kill the notification and get out.
    // TODO: Have a "There are no connected players" notification text.
    if (activePlayer == null || activePlayerState == null) {
        clearOngoingNotification();
        return;
    }

    boolean playing = activePlayerState.isPlaying();

    // If the song is not playing and the user wants notifications only when playing then
    // kill the notification and get out.
    if (!playing && !mShowNotificationWhenNotPlaying) {
        clearOngoingNotification();
        return;
    }

    // If there's no current song then kill the notification and get out.
    // TODO: Have a "There's nothing playing" notification text.
    final Song currentSong = activePlayerState.getCurrentSong();
    if (currentSong == null) {
        clearOngoingNotification();
        return;
    }

    // Compare the current state with the state when the notification was last updated.
    // If there are no changes (same song, same playing state) then there's nothing to do.
    String songName = currentSong.getName();
    String albumName = currentSong.getAlbumName();
    String artistName = currentSong.getArtist();
    Uri url = currentSong.getArtworkUrl();
    String playerName = activePlayer.getName();

    if (mNotifiedPlayerState == null) {
        mNotifiedPlayerState = new PlayerState();
    } else {
        boolean lastPlaying = mNotifiedPlayerState.isPlaying();
        Song lastNotifiedSong = mNotifiedPlayerState.getCurrentSong();

        // No change in state
        if (playing == lastPlaying && currentSong.equals(lastNotifiedSong)) {
            return;
        }
    }

    mNotifiedPlayerState.setCurrentSong(currentSong);
    mNotifiedPlayerState.setPlayStatus(activePlayerState.getPlayStatus());
    final NotificationManagerCompat nm = NotificationManagerCompat.from(this);

    PendingIntent nextPendingIntent = getPendingIntent(ACTION_NEXT_TRACK);
    PendingIntent prevPendingIntent = getPendingIntent(ACTION_PREV_TRACK);
    PendingIntent playPendingIntent = getPendingIntent(ACTION_PLAY);
    PendingIntent pausePendingIntent = getPendingIntent(ACTION_PAUSE);
    PendingIntent closePendingIntent = getPendingIntent(ACTION_CLOSE);

    Intent showNowPlaying = new Intent(this, NowPlayingActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, showNowPlaying, 0);
    Notification notification;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final Notification.Builder builder = new Notification.Builder(this);
        builder.setContentIntent(pIntent);
        builder.setSmallIcon(R.drawable.squeezer_notification);
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        builder.setShowWhen(false);
        builder.setContentTitle(songName);
        builder.setContentText(albumName);
        builder.setSubText(playerName);
        builder.setStyle(new Notification.MediaStyle().setShowActionsInCompactView(1, 2)
                .setMediaSession(mMediaSession.getSessionToken()));

        final MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder();
        metaBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, artistName);
        metaBuilder.putString(MediaMetadata.METADATA_KEY_ALBUM, albumName);
        metaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, songName);
        mMediaSession.setMetadata(metaBuilder.build());

        // Don't set an ongoing notification, otherwise wearable's won't show it.
        builder.setOngoing(false);

        builder.setDeleteIntent(closePendingIntent);
        if (playing) {
            builder.addAction(
                    new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_pause, "Pause", pausePendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent));
        } else {
            builder.addAction(
                    new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_play, "Play", playPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent));
        }

        ImageFetcher.getInstance(this).loadImage(url,
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height),
                new ImageWorker.ImageWorkerCallback() {
                    @Override
                    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                    public void process(Object data, @Nullable Bitmap bitmap) {
                        if (bitmap == null) {
                            bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_album_noart);
                        }

                        metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
                        metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
                        mMediaSession.setMetadata(metaBuilder.build());
                        builder.setLargeIcon(bitmap);
                        nm.notify(PLAYBACKSERVICE_STATUS, builder.build());
                    }
                });
    } else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

        builder.setOngoing(true);
        builder.setCategory(NotificationCompat.CATEGORY_SERVICE);
        builder.setSmallIcon(R.drawable.squeezer_notification);

        RemoteViews normalView = new RemoteViews(this.getPackageName(), R.layout.notification_player_normal);
        RemoteViews expandedView = new RemoteViews(this.getPackageName(),
                R.layout.notification_player_expanded);

        normalView.setOnClickPendingIntent(R.id.next, nextPendingIntent);

        expandedView.setOnClickPendingIntent(R.id.previous, prevPendingIntent);
        expandedView.setOnClickPendingIntent(R.id.next, nextPendingIntent);

        builder.setContent(normalView);

        normalView.setTextViewText(R.id.trackname, songName);
        normalView.setTextViewText(R.id.albumname, albumName);

        expandedView.setTextViewText(R.id.trackname, songName);
        expandedView.setTextViewText(R.id.albumname, albumName);
        expandedView.setTextViewText(R.id.player_name, playerName);

        if (playing) {
            normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause);
            normalView.setOnClickPendingIntent(R.id.pause, pausePendingIntent);

            expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause);
            expandedView.setOnClickPendingIntent(R.id.pause, pausePendingIntent);
        } else {
            normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_play);
            normalView.setOnClickPendingIntent(R.id.pause, playPendingIntent);

            expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_play);
            expandedView.setOnClickPendingIntent(R.id.pause, playPendingIntent);
        }

        builder.setContentTitle(songName);
        builder.setContentText(getString(R.string.notification_playing_text, playerName));
        builder.setContentIntent(pIntent);

        notification = builder.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notification.bigContentView = expandedView;
        }

        nm.notify(PLAYBACKSERVICE_STATUS, notification);

        ImageFetcher.getInstance(this).loadImage(this, url, normalView, R.id.album,
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_width),
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_height), nm,
                PLAYBACKSERVICE_STATUS, notification);
        ImageFetcher.getInstance(this).loadImage(this, url, expandedView, R.id.album,
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_width),
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_height), nm,
                PLAYBACKSERVICE_STATUS, notification);
    }
}

From source file:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java

private void updateMetadata(final Video video) {
    final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();

    metadataBuilder.putString(MediaMetadata.METADATA_KEY_MEDIA_ID, video.id + "");
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, video.title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, video.studio);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_DESCRIPTION, video.description);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, video.cardImageUrl);
    metadataBuilder.putLong(MediaMetadata.METADATA_KEY_DURATION, mDuration);

    // And at minimum the title and artist for legacy support
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, video.title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, video.studio);

    Glide.with(this).load(Uri.parse(video.cardImageUrl)).asBitmap().into(new SimpleTarget<Bitmap>(500, 500) {
        @Override//ww  w  .j  a  v a2 s .c  o  m
        public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
            metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
            mSession.setMetadata(metadataBuilder.build());
        }
    });
}