MediaMetadataCompat附加

有没有办法从支持库中使用MediaMetadataCompat的额外function?

使用MediaMetadata我可以设置额外的,但与compat一个我不能。

Solutions Collecting From Web of "MediaMetadataCompat附加"

希望能帮助到你。

  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()); 

我复制粘贴我们的代码。 请告诉我,如果你能理解它。

 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(); }