Colorize MediaStyle notification from album art

This commit is contained in:
Morgan Lim 2020-01-11 02:22:27 -05:00
parent 35a112509e
commit 507c9008aa
2 changed files with 5 additions and 2 deletions

View File

@ -36,6 +36,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.2.2' implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.media:media:1.1.0" implementation "androidx.media:media:1.1.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
} }
buildscript { buildscript {

View File

@ -31,6 +31,7 @@ import android.view.KeyEvent;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.media.app.NotificationCompat.MediaStyle; import androidx.media.app.NotificationCompat.MediaStyle;
import android.support.v4.media.session.MediaSessionCompat;
import net.nullsum.audinaut.R; import net.nullsum.audinaut.R;
import net.nullsum.audinaut.activity.SubsonicActivity; import net.nullsum.audinaut.activity.SubsonicActivity;
@ -67,7 +68,6 @@ public final class Notifications {
} }
final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -76,10 +76,12 @@ public final class Notifications {
.setComponent(new ComponentName(context, DownloadService.class)) .setComponent(new ComponentName(context, DownloadService.class))
.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP)); .putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP));
int[] compactActions = new int[]{0, 1, 2}; int[] compactActions = new int[]{0, 1, 2};
MediaSessionCompat mediaSession = new MediaSessionCompat(context, "Audinaut");
MediaStyle mediaStyle = new MediaStyle() MediaStyle mediaStyle = new MediaStyle()
.setShowActionsInCompactView(compactActions) .setShowActionsInCompactView(compactActions)
.setShowCancelButton(true) .setShowCancelButton(true)
.setCancelButtonIntent(PendingIntent.getService(context, 0, cancelIntent, 0)); .setCancelButtonIntent(PendingIntent.getService(context, 0, cancelIntent, 0))
.setMediaSession(mediaSession.getSessionToken());
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_PLAYING_ID) NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_PLAYING_ID)
.setChannelId(CHANNEL_PLAYING_ID) .setChannelId(CHANNEL_PLAYING_ID)