0

我正在建立一個音樂播放器的應用程序。我想在通知欄中實現媒體控制器。我已經嘗試過一種方法http://www.binpress.com/tutorial/using-android-media-style-notifications-with-media-session-controls/165。但它只支持android的棒棒糖版本。有沒有人有想法在通知欄中創建媒體控制器?如何在NotificationBar/LockScreen中構建支持api版本10的音樂控制器?

+1

使用Android支持library.http://developer.android。 com/tools/support-library/index.html – NovusMobile

+0

no use :(...不工作 –

+1

http://stackoverflow.com/questions/12526228/how-to-put-media-controller-button-on-notification-酒吧 – NovusMobile

回答

1

你必須NotificationCompat與MediaStyle使用:https://developer.android.com/reference/android/support/v7/app/NotificationCompat.MediaStyle.html

Notification noti = new NotificationCompat.Builder() 
.setSmallIcon(R.drawable.ic_stat_player) 
.setContentTitle("Track title") 
.setContentText("Artist - Album") 
.setLargeIcon(albumArtBitmap)) 
.setStyle(new NotificationCompat.MediaStyle() 
    .setMediaSession(mySession)) 
.build(); 

與NotificationCompat實施mediaSessionCompat的完整例子可以在這裏找到:https://bitbucket.org/nonameden/android-universalmusicplayer-compat/src/412465d6605fee26f197cc5615f7da15cc859d4a/mobile/src/main/java/com/example/android/uamp/MediaNotificationManager.java?at=master

+0

thanku :)我會試試這個一個:) –