Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaMetadataCompat Extras

Is there any way to use extras with the MediaMetadataCompat from the support library?

Using the MediaMetadata I can set extras, but with the compat one I cannot.

like image 911
gonzalomelov Avatar asked Oct 02 '15 18:10

gonzalomelov


2 Answers

Hope it helps.

 import android.support.v4.media.session.MediaSessionCompat;

   private MediaSessionCompat mMediaSession;
    //init mediasesson
    mMediaSession = new MediaSessionCompat(getApplicationContext(), "AudioPlayer",new ComponentName(this, HeadsetNotificationBroadcast.class), null);
    //set the metadata
    mMediaSession.setMetadata(new MediaMetadataCompat.Builder()
                    .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getSongDataHelper().getAlbumArt())
                    .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getSongDataHelper().getArtist())
                    .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getSongDataHelper().getAlbum())
                    .putString(MediaMetadataCompat.METADATA_KEY_TITLE, getSongDataHelper().getTitle())
                    .build());
like image 89
Reyansh Mishra Avatar answered Oct 21 '22 11:10

Reyansh Mishra


I have copy-pasted our code. Please tell me if you can understand it.

private static MediaInfo toCastMediaMetadata(MediaMetadataCompat track, JSONObject customData) {
        MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
        mediaMetadata.putString(MediaMetadata.KEY_TITLE, track.getDescription().getTitle().toString());
        mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, track.getDescription().getSubtitle().toString());
        mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST));
        mediaMetadata.putString(MediaMetadata.KEY_ALBUM_TITLE, track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM));
        WebImage image = new WebImage(new Uri.Builder().encodedPath(track.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI)).build());
        // First image is used by the receiver for showing the audio album art.
        mediaMetadata.addImage(image);
        // Second image is used by Cast Companion Library on the full screen activity that is shown
        // when the cast dialog is clicked.
        mediaMetadata.addImage(image);

        return new MediaInfo.Builder(
            track.getDescription().getExtras().getString(MutableMediaMetadataCompat.
                METADATA_KEY_TRACK_SOURCE)).setContentType(
            MIME_TYPE_AUDIO_MPEG).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setMetadata(mediaMetadata).setCustomData(customData).build();
    }
like image 22
gonzalomelov Avatar answered Oct 21 '22 11:10

gonzalomelov