October 2018
Intermediate to advanced
464 pages
15h 17m
English
Having your app respond to media controls (like on headphones), such as Play, Pause, Skip, and so on, is a nice touch your users will appreciate. Android makes this possible through the media library. As with the Playing sound effects with SoundPool recipe earlier, the Lollipop release changed how this is done. Unlike the SoundPool example, this recipe is able to take advantage of another approach, the compatibility library.
This recipe will show you how to set up MediaSession to respond to the hardware buttons, which will work on Lollipop and later, as well as previous Lollipop versions using the MediaSessionCompat library. (The compatibility library will take care of checking the OS version ...