I'm developing an application which should do an action whenever a user starts or stops music player in android. I researched on it and found a way to do. But it only receives events from only default music player. Other streaming player like Rdio, last.fm were left behind.
The code i used
Manifest.xml
<receiver
android:name=".MediaStateReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.android.music.playstatechanged" />
</intent-filter>
</receiver>
MediaStateReceiver.java
public class MediaStateReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
LogUtil.print("broadcast event recieved " + intent.getAction());
if(intent.hasExtra("playing")) {
Intent mediaIntent = new Intent(context, MusicStateChangeService.class);
mediaIntent.putExtra("MUSIC_STATE", true);
mediaIntent.putExtra("playing",intent.getBooleanExtra("playing",false));
context.startService(mediaIntent);
}
}
}
Is there any way to receive broadcast events from any music player.?