Java Code Examples for android.media.MediaMetadata#Builder

The following examples show how to use android.media.MediaMetadata#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicLibrary.java    From android-music-player with Apache License 2.0 6 votes vote down vote up
public static MediaMetadata getMetadata(Context ctx, String mediaId) {
    MediaMetadata metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(ctx, mediaId);

    // Since MediaMetadata is immutable, we need to create a copy to set the album art
    // We don't set it initially on all items so that they don't take unnecessary memory
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    for (String key: new String[]{MediaMetadata.METADATA_KEY_MEDIA_ID,
            MediaMetadata.METADATA_KEY_ALBUM, MediaMetadata.METADATA_KEY_ARTIST,
            MediaMetadata.METADATA_KEY_GENRE, MediaMetadata.METADATA_KEY_TITLE}) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadata.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
Example 2
Source File: MusicLibrary.java    From android-music-player with Apache License 2.0 6 votes vote down vote up
public static MediaMetadata getMetadata(Context ctx, String mediaId) {
    MediaMetadata metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(ctx, mediaId);

    // Since MediaMetadata is immutable, we need to create a copy to set the album art
    // We don't set it initially on all items so that they don't take unnecessary memory
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    for (String key: new String[]{MediaMetadata.METADATA_KEY_MEDIA_ID,
            MediaMetadata.METADATA_KEY_ALBUM, MediaMetadata.METADATA_KEY_ARTIST,
            MediaMetadata.METADATA_KEY_GENRE, MediaMetadata.METADATA_KEY_TITLE}) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadata.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
Example 3
Source File: MusicLibrary.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
public static MediaMetadata getMetadata(Context ctx, String mediaId) {
    MediaMetadata metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(ctx, mediaId);

    // Since MediaMetadata is immutable, we need to create a copy to set the album art
    // We don't set it initially on all items so that they don't take unnecessary memory
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    for (String key: new String[]{MediaMetadata.METADATA_KEY_MEDIA_ID,
            MediaMetadata.METADATA_KEY_ALBUM, MediaMetadata.METADATA_KEY_ARTIST,
            MediaMetadata.METADATA_KEY_GENRE, MediaMetadata.METADATA_KEY_TITLE}) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadata.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
Example 4
Source File: MusicLibrary.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
public static MediaMetadata getMetadata(Context ctx, String mediaId) {
    MediaMetadata metadataWithoutBitmap = music.get(mediaId);
    Bitmap albumArt = getAlbumBitmap(ctx, mediaId);

    // Since MediaMetadata is immutable, we need to create a copy to set the album art
    // We don't set it initially on all items so that they don't take unnecessary memory
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    for (String key: new String[]{MediaMetadata.METADATA_KEY_MEDIA_ID,
            MediaMetadata.METADATA_KEY_ALBUM, MediaMetadata.METADATA_KEY_ARTIST,
            MediaMetadata.METADATA_KEY_GENRE, MediaMetadata.METADATA_KEY_TITLE}) {
        builder.putString(key, metadataWithoutBitmap.getString(key));
    }
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION,
            metadataWithoutBitmap.getLong(MediaMetadata.METADATA_KEY_DURATION));
    builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, albumArt);
    return builder.build();
}
 
Example 5
Source File: AutoMediaBrowserService.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void initMediaMetaData( String id ) {

        for( Song song : mSongs ) {
            if( !TextUtils.isEmpty( song.getuId() ) && song.getuId().equalsIgnoreCase( id ) ) {
                MediaMetadata.Builder builder = new MediaMetadata.Builder();

                if( !TextUtils.isEmpty( song.getTitle() ) )
                    builder.putText( MediaMetadata.METADATA_KEY_TITLE, song.getTitle() );

                if( !TextUtils.isEmpty( song.getArtist() ) )
                    builder.putText( MediaMetadata.METADATA_KEY_ARTIST, song.getArtist() );

                if( !TextUtils.isEmpty( song.getGenre() ) )
                    builder.putText( MediaMetadata.METADATA_KEY_GENRE, song.getGenre() );

                if( !TextUtils.isEmpty( song.getAlbum() ) )
                    builder.putText( MediaMetadata.METADATA_KEY_ALBUM, song.getAlbum() );

                if( !TextUtils.isEmpty( song.getAlbumUrl() ) )
                    builder.putText( MediaMetadata.METADATA_KEY_ALBUM_ART_URI, song.getAlbumUrl() );

                mMediaSession.setMetadata( builder.build() );
            }
        }
    }
 
Example 6
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void handlePlayRequest() {
    delayedStopHandler.removeCallbacksAndMessages(null);
    if (!serviceStarted) {
        try {
            startService(new Intent(getApplicationContext(), MusicBrowserService.class));
        } catch (Throwable e) {
            FileLog.e(e);
        }
        serviceStarted = true;
    }

    if (!mediaSession.isActive()) {
        mediaSession.setActive(true);
    }

    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null) {
        return;
    }
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION, messageObject.getDuration() * 1000);
    builder.putString(MediaMetadata.METADATA_KEY_ARTIST, messageObject.getMusicAuthor());
    builder.putString(MediaMetadata.METADATA_KEY_TITLE, messageObject.getMusicTitle());
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
    if (audioInfo != null) {
        Bitmap bitmap = audioInfo.getCover();
        if (bitmap != null) {
            builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
        }
    }
    mediaSession.setMetadata(builder.build());
}
 
Example 7
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void handlePlayRequest() {
    delayedStopHandler.removeCallbacksAndMessages(null);
    if (!serviceStarted) {
        try {
            startService(new Intent(getApplicationContext(), MusicBrowserService.class));
        } catch (Throwable e) {
            FileLog.e(e);
        }
        serviceStarted = true;
    }

    if (!mediaSession.isActive()) {
        mediaSession.setActive(true);
    }

    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null) {
        return;
    }
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION, messageObject.getDuration() * 1000);
    builder.putString(MediaMetadata.METADATA_KEY_ARTIST, messageObject.getMusicAuthor());
    builder.putString(MediaMetadata.METADATA_KEY_TITLE, messageObject.getMusicTitle());
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
    if (audioInfo != null) {
        Bitmap bitmap = audioInfo.getCover();
        if (bitmap != null) {
            builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
        }
    }
    mediaSession.setMetadata(builder.build());
}
 
Example 8
Source File: NotificationService.java    From RoMote with Apache License 2.0 5 votes vote down vote up
private void updateMediaSessionMetadata(final Channel channel, final Bitmap bitmap) {
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    builder.putString(MediaMetadata.METADATA_KEY_TITLE, channel.getTitle());
    builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);

    mediaSession.setMetadata(builder.build());
}
 
Example 9
Source File: VideoPlayerActivity.java    From iview-android-tv with MIT License 5 votes vote down vote up
private void updateMediaSessionData() {
    if (mCurrentEpisode == null) {
        return;
    }
    final MediaMetadata.Builder builder = new MediaMetadata.Builder();

    updatePlaybackState(ExoPlayer.STATE_IDLE);

    updateMediaSessionIntent();

    builder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, mCurrentEpisode.getSeriesTitle());
    builder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, mCurrentEpisode.getTitle());
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION, mCurrentEpisode.getDuration() * 1000);

    builder.putString(MediaMetadata.METADATA_KEY_TITLE, mCurrentEpisode.getSeriesTitle());
    builder.putString(MediaMetadata.METADATA_KEY_ARTIST, mCurrentEpisode.getTitle());

    Point size = new Point(getResources().getDimensionPixelSize(R.dimen.card_width),
            getResources().getDimensionPixelSize(R.dimen.card_height));

    Picasso.with(this).load(mCurrentEpisode.getThumbnail()).resize(size.x, size.y).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            builder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
            mediaSession.setMetadata(builder.build());
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
        }
    });
}
 
Example 10
Source File: MediaServiceHandler.java    From Aerlink-for-Android with MIT License 5 votes vote down vote up
private void updateMetadata() {
    MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();

    if (mediaTitle == null && mediaArtist == null) {
        metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, "No info");
    }
    else {
        // And at minimum the title and artist for legacy support
        metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, mediaTitle);
        metadataBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, mediaArtist);
    }

    // Add any other fields you have for your data as well
    mSession.setMetadata(metadataBuilder.build());
}
 
Example 11
Source File: MusicBrowserService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void handlePlayRequest() {
    delayedStopHandler.removeCallbacksAndMessages(null);
    if (!serviceStarted) {
        try {
            startService(new Intent(getApplicationContext(), MusicBrowserService.class));
        } catch (Throwable e) {
            FileLog.e(e);
        }
        serviceStarted = true;
    }

    if (!mediaSession.isActive()) {
        mediaSession.setActive(true);
    }

    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null) {
        return;
    }
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION, messageObject.getDuration() * 1000);
    builder.putString(MediaMetadata.METADATA_KEY_ARTIST, messageObject.getMusicAuthor());
    builder.putString(MediaMetadata.METADATA_KEY_TITLE, messageObject.getMusicTitle());
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
    if (audioInfo != null) {
        Bitmap bitmap = audioInfo.getCover();
        if (bitmap != null) {
            builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
        }
    }
    mediaSession.setMetadata(builder.build());
}
 
Example 12
Source File: PlaybackActivity.java    From BuildingForAndroidTV with MIT License 5 votes vote down vote up
private void updateMetadata(final Movie movie) {
    final MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder();

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

    metadataBuilder.putString(MediaMetadata.METADATA_KEY_MEDIA_ID, movie.getId());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title);
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE,
            movie.getStudio());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_DESCRIPTION,
            movie.getDescription());
    metadataBuilder.putString(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI,
            movie.getCardImageUrl());
    metadataBuilder.putLong(MediaMetadata.METADATA_KEY_DURATION, mDuration);

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

    Glide.with(this)
        .load(Uri.parse(movie.getCardImageUrl()))
        .asBitmap()
        .into(new SimpleTarget<Bitmap>(500, 500) {
            @Override
            public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
                mSession.setMetadata(metadataBuilder.build());
            }
        });
}
 
Example 13
Source File: ClementineMediaSessionV21.java    From Android-Remote with GNU General Public License v3.0 5 votes vote down vote up
private void updateMetaData() {
    MySong song = App.Clementine.getCurrentSong();
    if (song != null && song.getArt() != null) {
        MediaMetadata.Builder builder = new MediaMetadata.Builder();
        builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, song.getArt());
        builder.putString(MediaMetadata.METADATA_KEY_ALBUM, song.getAlbum());
        builder.putString(MediaMetadata.METADATA_KEY_TITLE, song.getTitle());
        builder.putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, song.getAlbumartist());
        builder.putString(MediaMetadata.METADATA_KEY_ARTIST, song.getArtist());

        mMediaSession.setMetadata(builder.build());
    }
}
 
Example 14
Source File: MusicBrowserService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void handlePlayRequest() {
    delayedStopHandler.removeCallbacksAndMessages(null);
    if (!serviceStarted) {
        try {
            startService(new Intent(getApplicationContext(), MusicBrowserService.class));
        } catch (Throwable e) {
            FileLog.e(e);
        }
        serviceStarted = true;
    }

    if (!mediaSession.isActive()) {
        mediaSession.setActive(true);
    }

    MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null) {
        return;
    }
    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    builder.putLong(MediaMetadata.METADATA_KEY_DURATION, messageObject.getDuration() * 1000);
    builder.putString(MediaMetadata.METADATA_KEY_ARTIST, messageObject.getMusicAuthor());
    builder.putString(MediaMetadata.METADATA_KEY_TITLE, messageObject.getMusicTitle());
    AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
    if (audioInfo != null) {
        Bitmap bitmap = audioInfo.getCover();
        if (bitmap != null) {
            builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
        }
    }
    mediaSession.setMetadata(builder.build());
}
 
Example 15
Source File: MediaMetadataCompatApi21.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static Object newInstance() {
    return new MediaMetadata.Builder();
}