Skip to content

Commit

Permalink
Fixed fetching the playing track ID on old Android versions that use …
Browse files Browse the repository at this point in the history
…ints for the IDs.
  • Loading branch information
jjc1138 committed Mar 6, 2011
1 parent 3aef51d commit b90174f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/net/jjc1138/android/scrobbler/ScrobblerService.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ class IncompleteMetadataException extends InvalidMetadataException {
class Track implements Serializable { class Track implements Serializable {
private static final String sources = "PREU"; private static final String sources = "PREU";


public static long getID(Intent i) {
// It might be in a long extra or an int extra, so we have to check
// both:
final int def = -1;
long id = i.getLongExtra("id", def);
if (id != def) {
return id;
}
return i.getIntExtra("id", def);
}

public Track(Intent i, Context c) throws InvalidMetadataException { public Track(Intent i, Context c) throws InvalidMetadataException {
String iSource = i.getStringExtra("source"); String iSource = i.getStringExtra("source");
if (iSource == null || iSource.length() < 1) { if (iSource == null || iSource.length() < 1) {
Expand All @@ -75,7 +86,7 @@ public Track(Intent i, Context c) throws InvalidMetadataException {
} }
} }


id = i.getLongExtra("id", -1); id = getID(i);


if (id != -1) { if (id != -1) {
final String[] columns = new String[] { final String[] columns = new String[] {
Expand Down Expand Up @@ -653,7 +664,7 @@ private void enqueue(QueueEntry entry) {
private void handleIntent(Intent intent) { private void handleIntent(Intent intent) {
Log.v(LOG_TAG, "Status: " + Log.v(LOG_TAG, "Status: " +
((intent.getBooleanExtra("playing", false) ? "playing" : "stopped") ((intent.getBooleanExtra("playing", false) ? "playing" : "stopped")
+ " track " + intent.getLongExtra("id", -1))); + " track " + Track.getID(intent)));


if (!prefs.getBoolean("enable", true)) { if (!prefs.getBoolean("enable", true)) {
return; return;
Expand Down

0 comments on commit b90174f

Please sign in to comment.