Android developer's blog recently had a post about Musixmatch and Android's unique feature (Intents) being used effectively by the app.
It looks like Musixmatch finds the track info and then displays the lyrics in a floating dialog window via SYSTEM_ALERT_WINDOW. So what kind of intent is musixmatch listening to? Turns out, Spotify has a feature where in an intent is broadcast as soon as Playback is started. This can be turned off by the user via Spotify's native app settings "Device Broadcast Status". musixmatch just registers for this intent and acts accordingly.
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String artist = intent.getStringExtra("artist");
String album = intent.getStringExtra("album");
String track = intent.getStringExtra("track");
Toast.makeText(MyActivity.this, "Artist [" + artist + "], Album [" + album + "], Track [" + track + "]", Toast.LENGTH_SHORT).show();
}
};
private void registerSpotifyBroadcastIntents() {
IntentFilter filter = new IntentFilter();
filter.addAction("com.spotify.music.metadatachanged");
this.registerReceiver(mReceiver, filter);
}
This was tested in Spotify version 1.7.0.830 and could potentially change in a future version.
It looks like Musixmatch finds the track info and then displays the lyrics in a floating dialog window via SYSTEM_ALERT_WINDOW. So what kind of intent is musixmatch listening to? Turns out, Spotify has a feature where in an intent is broadcast as soon as Playback is started. This can be turned off by the user via Spotify's native app settings "Device Broadcast Status". musixmatch just registers for this intent and acts accordingly.
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String artist = intent.getStringExtra("artist");
String album = intent.getStringExtra("album");
String track = intent.getStringExtra("track");
Toast.makeText(MyActivity.this, "Artist [" + artist + "], Album [" + album + "], Track [" + track + "]", Toast.LENGTH_SHORT).show();
}
};
private void registerSpotifyBroadcastIntents() {
IntentFilter filter = new IntentFilter();
filter.addAction("com.spotify.music.metadatachanged");
this.registerReceiver(mReceiver, filter);
}
This was tested in Spotify version 1.7.0.830 and could potentially change in a future version.
No comments:
Post a Comment