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 :)我会试试这个一个:) –