2017-02-19 9 views
9

내 응용 프로그램에서 내 미디어 플레이어 서비스의 오디오 재생을 처리하기 위해 MediaSessionCompat을 사용하고 있습니다. 특히, 현재 노래의 메타 데이터를 블루투스 장치 (작동)에 브로드 캐스팅하고 잠금 화면 이미지를 현재 노래의 앨범 아트로 설정하려고합니다. Set lock screen background in Android (like Spotify do)MediaMetadataCompat METADATA_KEY_ART는 처음으로 이미지 만 설정합니다.

그래서 같은 MediaSessionCompat에서 현재 MediaMetadataCompatPlaybackStateCompat 오프 때마다 노래 변경, 내가 먼저 명확 :이 질문에 대한 유사

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(); 

다음으로 새 메타 데이터를 내 블루투스 장치의 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 방법은 잠금 화면에 표시된다. 이렇게하면 알림 자체에 표시되지만 잠금 화면 배경에는 표시되지 않습니다. 당신이 필요로하는 무엇

답변

1

VISIBILITY_PUBLIC 값이 @ianhanniballake https://gist.github.com/ianhanniballake/47617ec3488e0257325c

하여이 요점을 볼 당신이 여기에서 설정 한 정보는 추가 정보를 위해 잠금 화면

에서 볼 수있게된다

MediaControllerCompat controller = mediaSession.getController(); 
MediaMetadataCompat mediaMetadata = controller.getMetadata(); 
MediaDescriptionCompat description = mediaMetadata.getDescription(); 

NotificationCompat.Builder builder = new NotificationCompat.Builder(context); 

builder.setContentTitle(description.getTitle()) 
    .setContentText(description.getSubtitle()) 
    .setSubText(description.getDescription()) 
    .setLargeIcon(description.getIconBitmap()) 
    .setContentIntent(controller.getSessionActivity()) 
    .setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context,PlaybackStateCompat.ACTION_STOP)) 
        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); 

MediaStyle 통지입니다

+0

'setVisibility' 메소드는 보안 잠금 화면에 나타나는 정보와 관련이있는 것으로 보입니다. 내 미디어 알림에이 메서드를 추가해도 동작이 변경되지 않았습니다. –

+0

@AndrewBrooke 정보가 변경 될 때마다 ** 새 ** 알림을 만들어 게시해야합니다. – pantos27

+0

그게 내가 현재하고있는거야. 알림이 업데이트되지만 처음에는 잠금 화면의 이미지가 표시되지 않습니다. –