Before that occurs of course, here is the onStartCommand hook method.
This is another one of these lifecycle hook methods that is called back
by the activityManager service after the music service has been started.
And when it's going to receive the intent that was passed by the client.
And what we do here, is we go ahead and
we fish out the URL from the data portion of the intent.
So now we have a songURL.
If we're currently playing a song, we're going to stop playing the current song.
And in either case, we're going to go ahead and
set that songURL as the data source.
We'll then you're going to say setOnPreparedListener,
passing ourselves in, passing in this.
That means we're going to get a callback later.
And we'll look at that in a minute.
And then, we go ahead and we say to the media player object,
please prepare yourself asynchronously which means, go ahead and
start downloading portions of that song, but don't block the UI thread.
And notice how we return the START_NOT_STICKY flag.
We'll talk more about START_NOT_STICKY later.
What that means is don't restart the service if it gets shut down
involuntarily.
Here is the onBind method.
This is another hook method that's automatically called back by
android's activity manager service.
And this simply returns null to indicate that this is a started service,
not a bound service.
Down here we see the onPrepared method, which is what's implemented.
If you go up here and take a quick look,
you'll see that this class implements the media player onPreparedListener interface.
And this is the hook method called onPrepared.
It's called back, When the song has got enough content to start playing.
And what we do here is we go ahead and
set this thing to only play the song once rather than looping.
Indicate the song is now playing, and then we start playing the song.
And then at that point, the song will play out in the background.