use of android.media.session.MediaSession in project TicktockMusic by Lauzy.
the class TickNotification method buildNotification.
private Notification buildNotification(MusicService musicService) {
PendingIntent playIntent = createAction(musicService, MusicService.ACTION_PLAY);
PendingIntent pauseIntent = createAction(musicService, MusicService.ACTION_PAUSE);
PendingIntent previousIntent = createAction(musicService, MusicService.ACTION_LAST);
PendingIntent nextIntent = createAction(musicService, MusicService.ACTION_NEXT);
PendingIntent contentIntent = PendingIntent.getActivity(musicService, 0, new Intent(musicService, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
boolean isPlaying = musicService.getPlaybackState().getState() == PlaybackState.STATE_PLAYING;
MediaSession session = musicService.getMediaSession();
MediaController controller = session.getController();
if (controller.getMetadata() != null) {
MediaDescription description = controller.getMetadata().getDescription();
NotificationCompat.Builder builder = new NotificationCompat.Builder(musicService);
builder.setContentTitle(description.getTitle()).setSmallIcon(R.drawable.ic_notification).setShowWhen(false).setOngoing(isPlaying).setContentIntent(contentIntent).setLargeIcon(description.getIconBitmap()).setContentTitle(description.getTitle()).setContentText(description.getSubtitle()).addAction(R.drawable.ic_skip_previous_notify, "", previousIntent).addAction(isPlaying ? R.drawable.ic_pause : R.drawable.ic_play, "", isPlaying ? pauseIntent : playIntent).addAction(R.drawable.ic_skip_next_notify, "", nextIntent).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(0, 1, 2));
if (description.getIconBitmap() != null) {
Palette palette = Palette.from(description.getIconBitmap()).generate();
int color = palette.getDominantColor(ThemeHelper.getThemeColorResId(musicService.getApplicationContext()));
builder.setColor(color);
}
return builder.build();
}
return null;
}
Aggregations