Slide 1

Slide 1 text

Android Media Hacks @KeithYokoma - Drivemode, Inc. potatotips #18

Slide 2

Slide 2 text

@KeithYokoma Keishin Yokomaku at Drivemode, Inc. as Android Engineer Experience 1.SNS client and photo book application for Android 2.Driver’s application for Android Publications 1.Android Training 2.Mixi official smartphone application development guide Like Motorsport, Bicycle, Photography, Tumblr

Slide 3

Slide 3 text

Media Playback Control Put media playback controller on… • Notification • AppWidgets • Android Auto App • Lock Screen(KeyGuard)

Slide 4

Slide 4 text

Media Playback Control Different implementations for each API level • RemoteController (from KitKat) • RemoteControlClient(from ICS) These system are based on PendingIntent From Lollipop… • MediaSession and MediaController

Slide 5

Slide 5 text

MediaController Standardized media playback control API from Lollipop System will use this API in… • Notification.MediaStyle • Android Auto App

Slide 6

Slide 6 text

How it works on Notification Media Application MediaSession System Notification MediaController Token Transport Control

Slide 7

Slide 7 text

How it works on Android Auto Media Application MediaSession Android Auto MediaController Token & Media Contents Bind MediaBrowserService MediaBrowser Token Token Transport Control

Slide 8

Slide 8 text

Watching Notification…

Slide 9

Slide 9 text

NotificationListenerService

Slide 10

Slide 10 text

NotificationListenerService Event receiver for status bar notification available from JB-MR2 We can access following data in the notification… • Title • Message • ContentView • HeadsUpContentView • Extras

Slide 11

Slide 11 text

NotificationListenerService Event receiver for status bar notification available from JB-MR2 We can access following data in the notification… • Title • Message • ContentView • HeadsUpContentView • Extras

Slide 12

Slide 12 text

Notification.MediaStyle

Slide 13

Slide 13 text

Notification.MediaStyle

Slide 14

Slide 14 text

MediaController

Slide 15

Slide 15 text

MediaController

Slide 16

Slide 16 text

–Me “Yes, you can steal a media session token without invading private APIs”

Slide 17

Slide 17 text

–Me “And you can set the token to your own MediaController”

Slide 18

Slide 18 text

–Someone “This is more like session hijacking”

Slide 19

Slide 19 text

Take control of music playback public class MusicNotificationWatcher extends NotificationListenerService { private Bus eventBus; @Override public void onNotificationPosted(StatusBarNotification sbn) { MediaSession.Token token = sbn.getNotification().extras.getParcelable(Notification.EXTRA_MEDIA_SESSION); eventBus.post(new NewMusicNotification(token)); } } public class MyActivity extends Activity { private MediaController controller; @Subscribe public void onNewMusicNotificationAdded(NewMusicNotification event) { controller = new MediaController(this, event.getToken()) } }

Slide 20

Slide 20 text

Take control of music playback public class MusicNotificationWatcher extends NotificationListenerService { private Bus eventBus; @Override public void onNotificationPosted(StatusBarNotification sbn) { MediaSession.Token token = sbn.getNotification().extras.getParcelable(Notification.EXTRA_MEDIA_SESSION); eventBus.post(new NewMusicNotification(token)); } } public class MyActivity extends Activity { private MediaController controller; @Subscribe public void onNewMusicNotificationAdded(NewMusicNotification event) { controller = new MediaController(this, event.getToken()) } }

Slide 21

Slide 21 text

Take control of music playback public class MusicNotificationWatcher extends NotificationListenerService { private Bus eventBus; @Override public void onNotificationPosted(StatusBarNotification sbn) { MediaSession.Token token = sbn.getNotification().extras.getParcelable(Notification.EXTRA_MEDIA_SESSION); eventBus.post(new NewMusicNotification(token)); } } public class MyActivity extends Activity { private MediaController controller; @Subscribe public void onNewMusicNotificationAdded(NewMusicNotification event) { controller = new MediaController(this, event.getToken()) } }

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

It only works for Google Play Music

Slide 24

Slide 24 text

Conclusion • Do not put PRIVATE things on your notification • Crackers are watching you • Consider using MediaSession and MediaController • For better interaction with Auto, Notification and
 your partners’ applications

Slide 25

Slide 25 text

Conclusion • For a OS compatibility reason, you can use RemoteControlClient and AudioManager • Still you need some dirty hacks… • For an application compatibility reason, you should use RemoteController • Even though it is deprecated now, it works on Lollipop

Slide 26

Slide 26 text

Android Media Hacks @KeithYokoma - Drivemode, Inc. potatotips #18