私のアプリケーションでは、私はMediaSessionCompat
を使用して、メディアプレーヤーサービスからのオーディオの再生を処理しています。特に、現在の曲のメタデータをブルートゥースデバイス(動作する)にブロードキャストし、現在の曲のアルバムアートにロック画面を設定したいと考えています。 Set lock screen background in Android (like Spotify do)MediaMetadataCompat METADATA_KEY_ARTは初めて画像を設定します
そうのようなMediaSessionCompat
から現在MediaMetadataCompat
とPlaybackStateCompat
オフするたびに曲の変更、私が最初に明確:この質問に似て
mSession.setActive(false);
mSession.setMetadata(null);
mSession.setPlaybackState(null);
その後、私はそれらの新しいインスタンスを作成しますそれぞれのビルダーのクラス
MediaMetadataCompat metadata = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_TITLE,
songName)
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST,
artistName)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM,
albumName)
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, durationMs)
.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
.build();
PlaybackStateCompat state = new PlaybackStateCompat.Builder()
.setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PAUSE |
PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)
.setState(PlaybackStateCompat.STATE_PLAYING, positionMs, 1.0f, SystemClock.elapsedRealtime())
.build();
次に、私は新しいメタデータを設定します私のBluetoothデバイスでMediaSessionCompat
mSession.setActive(true);
mSession.setMetadata(metadata);
mSession.setPlaybackState(state);
、メタデータは正常に動作し、毎回曲の変更を変更します。しかし、私の電話では、ロック画面のアルバムカバーは初めて更新されます。私が設定しているビットマップが新しいものであることを確認しましたが、イメージは変わりません。
また、サービスでメディアスタイルの通知を作成して、ユーザーが永続的な通知とロック画面から音楽を制御できるようにします。
NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();
style.setShowActionsInCompactView(0, 1, 2, 3, 4);
Intent intent = new Intent(this, DestinationActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(pendingIntent)
.setStyle(style)
.setContentTitle(songName)
.setContentText(artistName)
.setLargeIcon(bitmap);
// Code to set notification actions
startForeground(NOTIFICATION_ID_PLAYER_CONTROLS, builder.build());
しかし、私のメディア通知用setLargeIcon
方法は、ロック画面に表示されているアルバムカバーには影響しません。これにより通知画面に表示されますが、ロック画面の背景としては表示されません。あなたが必要なもの
'setVisibility'メソッドは、安全なロック画面に表示される情報と関係しているようです。このメソッドを自分のメディア通知に追加しても、動作は変更されませんでした。 –
@AndrewBrooke **新しい**通知を作成し、情報が変更されるたびに投稿する必要があります。 – pantos27
それは私が現在やっていることです。通知は更新されますが、ロック画面の画像は初めてです。 –