Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

8. Movies and Music > Longer-Running Music Playback

Longer-Running Music Playback

You didn’t think I’d let you off that easy, did you? Remember two chapters ago when I showed you how to build a service in a separate process by using an AIDL file? I told you you’d need it for longer-running music playback. Here’s a quick recap of that process:

1. Create a service, define a few methods to control music playback, and declare the service in your manifest.

2. Create an Android Interface Definition Language (AIDL) file to define how the service will talk to any of the activities.

3. Bind an activity to the service, and, when the callback is hit, save the binder in order to call the service’s methods.

If most, or any, of those steps don’t make sense, take a gander back at Chapter 6.

In this section, I’ll show you how to turn the empty service into one that actually plays music in the background. The example music service will have methods to pause, play, set a data source, and ask it what the title of the current song is. To show you this service in practice, I’ll have my activity play the most recently added song on my new background music service.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial