java获取MediaPlayer相册艺术作为位图
嘿,大家好,所以我一直在使用媒体播放应用程序,所以我尝试让通知控制媒体,这样一切都可以正常工作,除了通知中的媒体样式不接受中的相册艺术。setLargeIcont()所以我需要一种方法将专辑艺术作为位图
public void showNotification(int playPauseBtn) {
Bitmap bitmap=null;
try {
uri = Uri.parse(listSongs.get(position).getPath());
byte[] image = getAlbumArt(listSongs.get(position).getPath());
bitmap = MediaStore.Images.Media.getBitmap(
context.getContentResolver(),uri);
bitmap= Bitmap.createScaledBitmap(bitmap,30,30,true);
}catch (FileNotFoundException exception) {
exception.printStackTrace();
bitmap = BitmapFactory.decodeResource(context.getResources(),
R.drawable.main_bg);
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent(this, PlayerActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
Intent prevIntent = new Intent(this, NotificationReciever.class).setAction(ACTION_PREV);
PendingIntent prevPendindIntent = PendingIntent.getBroadcast(this, 0, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent playIntent = new Intent(this, NotificationReciever.class).setAction(ACTION_PLAY);
PendingIntent playPendindIntent = PendingIntent.getBroadcast(this, 0, playIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent nextIntent = new Intent(this, NotificationReciever.class).setAction(ACTION_NEXT);
PendingIntent nextPendindIntent = PendingIntent.getBroadcast(this, 0, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//Bitmap picture = BitmapFactory.decodeResource(getResources(), R.id.cover_art);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this, CHANNEL_ID_2)
.setSmallIcon(R.id.cover_art)
.setLargeIcon(bitmap)
.setContentTitle(listSongs.get(position).getTitle())
.setContentText(listSongs.get(position).getArtist())
.addAction(R.drawable.ic_skip_previous, "Previous", prevPendindIntent)
.addAction(playPauseBtn, "Play", playPendindIntent)
.addAction(R.drawable.ic_skip_next, "Next", nextPendindIntent)
.setStyle(new 安卓x.media.app.NotificationCompat.MediaStyle()
.setMediaSession(mediaSession.getSessionToken()))
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentIntent(contentIntent)
.setOnlyAlertOnce(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification.build());
}
共 (0) 个答案