private void setNotificationMetadata(MediaNotificationInfo.Builder builder) { MediaMetadata notificationMetadata = new MediaMetadata("", "", ""); builder.setMetadata(notificationMetadata); if (mCastDevice != null) notificationMetadata.setTitle(mCastDevice.getFriendlyName()); if (mMediaPlayer == null) return; com.google.android.gms.cast.MediaInfo info = mMediaPlayer.getMediaInfo(); if (info == null) return; com.google.android.gms.cast.MediaMetadata metadata = info.getMetadata(); if (metadata == null) return; String title = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_TITLE); if (title != null) notificationMetadata.setTitle(title); String artist = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ARTIST); if (artist == null) { artist = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_ARTIST); } if (artist != null) notificationMetadata.setArtist(artist); String album = metadata.getString(com.google.android.gms.cast.MediaMetadata.KEY_ALBUM_TITLE); if (album != null) notificationMetadata.setAlbum(album); }
@Override public CastSessionInfo getSessionInfo() { if (isApiClientInvalid()) return null; CastSessionInfo.VolumeInfo.Builder volumeBuilder = new CastSessionInfo.VolumeInfo.Builder() .setLevel(Cast.CastApi.getVolume(mApiClient)) .setMuted(Cast.CastApi.isMute(mApiClient)); CastSessionInfo.ReceiverInfo.Builder receiverBuilder = new CastSessionInfo.ReceiverInfo.Builder() .setLabel(mCastDevice.getDeviceId()) .setFriendlyName(mCastDevice.getFriendlyName()) .setVolume(volumeBuilder.build()) .setIsActiveInput(Cast.CastApi.getActiveInputState(mApiClient)) .setDisplayStatus(null) .setReceiverType("cast") .addCapabilities(getCapabilities(mCastDevice)); CastSessionInfo.Builder sessionInfoBuilder = new CastSessionInfo.Builder() .setSessionId(mSessionId) .setStatusText(mApplicationStatus) .setReceiver(receiverBuilder.build()) .setStatus("connected") .setTransportId("web-4") .addNamespaces(mNamespaces); if (mApplicationMetadata != null) { sessionInfoBuilder .setAppId(mApplicationMetadata.getApplicationId()) .setDisplayName(mApplicationMetadata.getName()); } else { sessionInfoBuilder .setAppId(mSource.getApplicationId()) .setDisplayName(mCastDevice.getFriendlyName()); } return sessionInfoBuilder.build(); }