7
Google은 진행중인 재생 알림을 Lollipop에 도입 된 MediaStyle 알림으로 마이그레이션하는 중입니다. RemoteControlClient가 더 이상 사용되지 않고 MediaStyle 알림이 미디어 버튼 이벤트 (예 : 헤드폰을 통해 일시 중지/재생 원격)를 처리하지 않습니다.MediaStyle 알림이 RemoteControl 이벤트에 응답하지 않습니다.
누구든지이 작품을 얻었습니까? MediaSessionCallback의 어떤 이벤트도 호출되지 않습니다. 재생 상태 설정
MediaSession mediaSession = (MediaSession) session.getMediaSession();
Notification.Builder builder =
new Notification.Builder(c)
.setDefaults(0)
.setSmallIcon(R.drawable.ic_notif)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentTitle(clip.getTitle())
.setContentText(clip.getSourceName())
.setProgress((int)duration, (int)progress, false)
.setWhen(0)
.setContentIntent(pendingIntent);
if (playing) {
builder.addAction(R.drawable.ic_media_pause, c.getString(R.string.media_pause),
getPendingIntentForKeyCode(app.getApplicationContext(), KeyEvent.KEYCODE_MEDIA_PAUSE));
} else {
builder.addAction(R.drawable.ic_media_play, c.getString(R.string.media_play),
getPendingIntentForKeyCode(app.getApplicationContext(), KeyEvent.KEYCODE_MEDIA_PLAY));
}
builder.addAction(R.drawable.ic_media_next, c.getString(R.string.media_next),
getPendingIntentForKeyCode(app.getApplicationContext(), KeyEvent.KEYCODE_MEDIA_NEXT));
builder.setStyle(new Notification.MediaStyle()
.setMediaSession(mediaSession.getSessionToken())
.setShowActionsInCompactView(new int[] {1, 2})
)
);
notification = builder.build();
Compat 라이브러리의 경우 다음과 유사해야합니다. PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder(); stateBuilder.setActions (PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS); stateBuilder.setState (PlaybackState.STATE_PLAYING, 0, 1); m_objMediaSession.setPlaybackState (stateBuilder.build()); – goRGon
^약간의 수정, 그것은'PlaybackStateCompat.ACTION_PLAY' 등이 될 것입니다. – hypd09