2014-10-21 3 views
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(); 

답변

5

: 여기

미디어 세션이 여기에

mSession = new MediaSessionCompat(this, TAG); 
    mSession.setCallback(new MediaSessionCallback()); 
    mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); 
    mSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC); 
    mSession.setActive(true); 

메타 데이터가 마지막으로 통지 코드를
MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder(); 
    metadataBuilder 
      .putLong(MediaMetadata.METADATA_KEY_DURATION, clip.getDuration()) 
      .putString(MediaMetadata.METADATA_KEY_MEDIA_ID, clip.getClipId()) 
      .putString(MediaMetadata.METADATA_KEY_TITLE, clip.getTitle()) 
      .putString(MediaMetadata.METADATA_KEY_ARTIST, clip.getSourceName()) 
      .putString(MediaMetadata.METADATA_KEY_ALBUM_ART_URI, clip.getImageUrl()) 
      .putLong(MediaMetadata.METADATA_KEY_DURATION, clip.getDuration()); 
    mSession.setMetadata(metadataBuilder.build()); 

을 설정하는 방법입니다 초기화하는 방법입니다 MediaSession에서 지원하는 작업 :

+2

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

+1

^약간의 수정, 그것은'PlaybackStateCompat.ACTION_PLAY' 등이 될 것입니다. – hypd09

관련 문제