views:

229

answers:

2

I'm planning on doing a application for Android 2.1 that changes song every minute (through what I hope exists in Android, "next") for the application using the audio device atm.

So if I have Spotify running in background already, playing music, can I through my program change to the next track?

Let me know if I was unclear about anything. Thanks in advance!

+1  A: 

There's no universal audio transport API for music applications, so you'd need to see if the music applications you're targeting publicly expose service bindings or intents. If not, you won't be able to do this.

Roman Nurik
A: 

The system music homescreen widget sends this intent for the built-in music player:

    final ComponentName serviceName = new ComponentName(context, 
        MediaPlaybackService.class);
    intent = new Intent(MediaPlaybackService.NEXT_ACTION);
    intent.setComponent(serviceName);
    pendingIntent = PendingIntent.getService(context,
            0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.control_next, pendingIntent);

But it looks like this might take some hackery to implement outside packages in the music app itself because the MediaPlaybackService only accepts explicit Intents and isn't accessible from the outside. This thread seems to indicate it's possible with a bit of hackery, though.

But even then, as Roman said, not every music player will respect that Intent. You'll have to check with Spotify/Pandora/Last.fm themselves and see if they have any available intents to bind like that.

Yoni Samlan
This sounds like what I'm after! Gonna dig into this a bit further and give it a try
parse
Can't get this to work, haven't tried it with Spotify yet. But I can't get the code to work, care to put it in a context on how to use it? I'm new to this whole Intent-thingie.
parse
Updated with some details after a bit of digging - looks to be rather unpleasant after all.
Yoni Samlan