Merge lp:~scottwferg/ubuntuone-android-music/last-fm-scrobbling into lp:ubuntuone-android-music

Proposed by Scott Ferguson
Status: Merged
Approved by: Chad Miller
Approved revision: 448
Merged at revision: 452
Proposed branch: lp:~scottwferg/ubuntuone-android-music/last-fm-scrobbling
Merge into: lp:ubuntuone-android-music
Diff against target: 202 lines (+80/-2)
6 files modified
assets/html/en/index.html (+12/-0)
res/values/strings.xml (+3/-0)
res/xml/settings.xml (+10/-0)
src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java (+4/-1)
src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java (+31/-0)
src/net/sourceforge/subsonic/androidapp/util/Constants.java (+20/-1)
To merge this branch: bzr merge lp:~scottwferg/ubuntuone-android-music/last-fm-scrobbling
Reviewer Review Type Date Requested Status
Chad Miller (community) Approve
Review via email: mp+37765@code.launchpad.net

Description of the change

Adds Last.fm scrobbling support via the official Last.fm app or Simple Last.fm Scrobbler. The SLS API was used for it's simplicity, and implicit support in the official app. The changes also include a settings option to enable/disable scrobbling (defaulting to off). The user is not required to login in any way within the app, it simply broadcasts an intent with the song information at relevant playstate changes.

To post a comment you must log in.
Revision history for this message
Chad Miller (cmiller) wrote :

Nice! Thank you.

Approving, but I'm emailing last.fm about their plans for future support of the SLS API.

review: Approve
Revision history for this message
Scott Ferguson (scottwferg) wrote :

> Nice! Thank you.
>
> Approving, but I'm emailing last.fm about their plans for future support of
> the SLS API.

Sounds good!

Revision history for this message
Scott Ferguson (scottwferg) wrote :

Just pushed up a small commit to address sending the STATE_COMPLETE intent when currentPlaying is null. Caused a crash when exiting the app or finishing a playlist.

447. By Scott Ferguson <scott@scott-laptop>

Only set song information if it's available, otherwise just mark the scrobble as complete

448. By Scott Ferguson

Merge lp:~cmiller/ubuntuone-android-music/last-fm-scrobbling

Revision history for this message
Chad Miller (cmiller) wrote :

Okay. I'm happy with this.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'assets/html/en/index.html'
--- assets/html/en/index.html 2010-09-01 14:23:38 +0000
+++ assets/html/en/index.html 2010-10-07 03:11:04 +0000
@@ -30,5 +30,17 @@
30 <li>Includes photos and contacts sync for iPhone and Android devices.</li><!-- May need to alter depending on the delivery date of photos sync -->30 <li>Includes photos and contacts sync for iPhone and Android devices.</li><!-- May need to alter depending on the delivery date of photos sync -->
31</ul>31</ul>
3232
33 <h2>Scrobbling</h2>
34
35 <p>If you use <a href="http://last.fm/">Last.fm</a> to track your music and get recommendations, then you can install an "scrobbling" app to to send playlist events. Ubuntu One Mobile Music Streaming supports a number of apps:</a></p>
36
37 <ul>
38 <li><i><disableda href="http://market.android.com/details?id=com.adam.aslfms">Simple Last.fm Scrobbler</disableda></i></li>
39 <li>official <i><disableda href="http://market.android.com/search?q=fm.last.android">Last.fm</disableda></i></li>
40 </ul>
41
42 <p>To use, enable scrobbling in the Ubuntu One Mobile Music Streaming settings, after you install and set up a scrobbling app.</p>
43
44
33</body>45</body>
34</html>46</html>
3547
=== modified file 'res/values/strings.xml'
--- res/values/strings.xml 2010-10-01 12:16:53 +0000
+++ res/values/strings.xml 2010-10-07 03:11:04 +0000
@@ -137,6 +137,9 @@
137 <string name="settings.cache_size_10000">10 GB</string>137 <string name="settings.cache_size_10000">10 GB</string>
138 <string name="settings.cache_size_20000">20 GB</string>138 <string name="settings.cache_size_20000">20 GB</string>
139 <string name="settings.cache_size_unlimited">Unlimited</string>139 <string name="settings.cache_size_unlimited">Unlimited</string>
140 <string name="settings.lastfm_title">Last.fm</string>
141 <string name="settings.lastfm_scrobble">Scrobbling Support</string>
142 <string name="settings.lastfm_description">Report plays to Last.fm app (see Help)</string>
140143
141 <string name="music_service.retry">A network error occurred. Retrying %d of %d.</string>144 <string name="music_service.retry">A network error occurred. Retrying %d of %d.</string>
142145
143146
=== modified file 'res/xml/settings.xml'
--- res/xml/settings.xml 2010-09-07 09:14:31 +0000
+++ res/xml/settings.xml 2010-10-07 03:11:04 +0000
@@ -34,4 +34,14 @@
3434
35 </PreferenceCategory>35 </PreferenceCategory>
3636
37 <PreferenceCategory
38 a:title="@string/settings.lastfm_title">
39 <CheckBoxPreference
40 a:title="@string/settings.lastfm_scrobble"
41 a:key="lastfmScrobbling"
42 a:defaultValue="false"
43 a:summary="@string/settings.lastfm_description"
44 />
45 </PreferenceCategory>
46
37</PreferenceScreen>47</PreferenceScreen>
3848
=== modified file 'src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java'
--- src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java 2010-08-23 06:27:00 +0000
+++ src/net/sourceforge/subsonic/androidapp/activity/SettingsActivity.java 2010-10-07 03:11:04 +0000
@@ -20,6 +20,7 @@
2020
21import android.content.SharedPreferences;21import android.content.SharedPreferences;
22import android.os.Bundle;22import android.os.Bundle;
23import android.preference.CheckBoxPreference;
23import android.preference.ListPreference;24import android.preference.ListPreference;
24import android.preference.PreferenceActivity;25import android.preference.PreferenceActivity;
25import android.util.Log;26import android.util.Log;
@@ -33,6 +34,7 @@
33 private ListPreference theme;34 private ListPreference theme;
34 private ListPreference cacheSize;35 private ListPreference cacheSize;
35 private ListPreference preloadCount;36 private ListPreference preloadCount;
37 private CheckBoxPreference lastfmScrobbling;
3638
37 @Override39 @Override
38 public void onCreate(Bundle savedInstanceState) {40 public void onCreate(Bundle savedInstanceState) {
@@ -42,6 +44,7 @@
42 theme = (ListPreference) findPreference(Constants.PREFERENCES_KEY_THEME);44 theme = (ListPreference) findPreference(Constants.PREFERENCES_KEY_THEME);
43 cacheSize = (ListPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);45 cacheSize = (ListPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);
44 preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT);46 preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT);
47 lastfmScrobbling = (CheckBoxPreference) findPreference(Constants.PREFERENCES_KEY_LASTFM_SCROBBLING);
4548
46 SharedPreferences prefs = Util.getPreferences(this);49 SharedPreferences prefs = Util.getPreferences(this);
47 prefs.registerOnSharedPreferenceChangeListener(this);50 prefs.registerOnSharedPreferenceChangeListener(this);
@@ -69,4 +72,4 @@
69 preloadCount.setSummary(preloadCount.getEntry());72 preloadCount.setSummary(preloadCount.getEntry());
70 }73 }
7174
72}
73\ No newline at end of file75\ No newline at end of file
76}
7477
=== modified file 'src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java'
--- src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java 2010-09-07 09:14:31 +0000
+++ src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java 2010-10-07 03:11:04 +0000
@@ -28,6 +28,7 @@
28import android.app.Service;28import android.app.Service;
29import android.content.Context;29import android.content.Context;
30import android.content.Intent;30import android.content.Intent;
31import android.content.SharedPreferences;
31import android.media.AudioManager;32import android.media.AudioManager;
32import android.media.MediaPlayer;33import android.media.MediaPlayer;
33import android.os.Handler;34import android.os.Handler;
@@ -38,6 +39,7 @@
38import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;39import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
39import net.sourceforge.subsonic.androidapp.domain.PlayerState;40import net.sourceforge.subsonic.androidapp.domain.PlayerState;
40import net.sourceforge.subsonic.androidapp.util.CancellableTask;41import net.sourceforge.subsonic.androidapp.util.CancellableTask;
42import net.sourceforge.subsonic.androidapp.util.Constants;
41import net.sourceforge.subsonic.androidapp.util.ShufflePlayBuffer;43import net.sourceforge.subsonic.androidapp.util.ShufflePlayBuffer;
42import net.sourceforge.subsonic.androidapp.util.SimpleServiceBinder;44import net.sourceforge.subsonic.androidapp.util.SimpleServiceBinder;
43import net.sourceforge.subsonic.androidapp.util.Util;45import net.sourceforge.subsonic.androidapp.util.Util;
@@ -226,8 +228,10 @@
226228
227 if (currentPlaying != null && showNotification) {229 if (currentPlaying != null && showNotification) {
228 Util.showPlayingNotification(this, handler, currentPlaying.getSong());230 Util.showPlayingNotification(this, handler, currentPlaying.getSong());
231 scrobbleLastfm(Constants.LASTFM_STATE_START);
229 } else {232 } else {
230 Util.hidePlayingNotification(this, handler);233 Util.hidePlayingNotification(this, handler);
234 scrobbleLastfm(Constants.LASTFM_STATE_COMPLETE);
231 }235 }
232 }236 }
233237
@@ -380,8 +384,10 @@
380384
381 if (this.playerState == PAUSED && playerState == PlayerState.STARTED) {385 if (this.playerState == PAUSED && playerState == PlayerState.STARTED) {
382 Util.showPlayingNotification(this, handler, currentPlaying.getSong());386 Util.showPlayingNotification(this, handler, currentPlaying.getSong());
387 scrobbleLastfm(Constants.LASTFM_STATE_START);
383 } else if (this.playerState == STARTED && playerState == PlayerState.PAUSED) {388 } else if (this.playerState == STARTED && playerState == PlayerState.PAUSED) {
384 Util.hidePlayingNotification(this, handler);389 Util.hidePlayingNotification(this, handler);
390 scrobbleLastfm(Constants.LASTFM_STATE_PAUSE);
385 }391 }
386392
387 this.playerState = playerState;393 this.playerState = playerState;
@@ -572,6 +578,31 @@
572 return revision;578 return revision;
573 }579 }
574580
581 private void scrobbleLastfm(final int aState) {
582 SharedPreferences prefs = Util.getPreferences(this);
583
584 if (prefs.getBoolean(Constants.PREFERENCES_KEY_LASTFM_SCROBBLING, false)) {
585 // Launch Last.fm intent here
586 Intent lastfm = new Intent();
587
588 lastfm.setAction(Constants.INTENT_SCROBBLE_LASTFM);
589 lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_APP_NAME, Constants.LASTFM_APP_NAME);
590 lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_APP_PACKAGE, Constants.LASTFM_APP_PACKAGE);
591
592 if (currentPlaying != null && currentPlaying.getSong() != null) {
593 lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_TRACK, currentPlaying.getSong().getTitle());
594 lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_ARTIST, currentPlaying.getSong().getArtist());
595 lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_ALBUM, currentPlaying.getSong().getAlbum());
596 // lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_PLAYER, Constants.LASTFM_APP_NAME);
597 lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_DURATION, currentPlaying.getSong().getDuration());
598 }
599
600 lastfm.putExtra(Constants.INTENT_EXTRA_LASTFM_STATE, aState);
601
602 sendBroadcast(lastfm);
603 }
604 }
605
575 private synchronized void cleanup() {606 private synchronized void cleanup() {
576 Iterator<DownloadFile> iterator = cleanupCandidates.iterator();607 Iterator<DownloadFile> iterator = cleanupCandidates.iterator();
577 while (iterator.hasNext()) {608 while (iterator.hasNext()) {
578609
=== modified file 'src/net/sourceforge/subsonic/androidapp/util/Constants.java'
--- src/net/sourceforge/subsonic/androidapp/util/Constants.java 2010-09-29 21:08:46 +0000
+++ src/net/sourceforge/subsonic/androidapp/util/Constants.java 2010-10-07 03:11:04 +0000
@@ -44,7 +44,25 @@
44 public static final String INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET = "subsonic.albumlistoffset";44 public static final String INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET = "subsonic.albumlistoffset";
45 public static final String INTENT_EXTRA_NAME_SHUFFLE = "subsonic.shuffle";45 public static final String INTENT_EXTRA_NAME_SHUFFLE = "subsonic.shuffle";
46 public static final String INTENT_EXTRA_NAME_REFRESH = "subsonic.refresh";46 public static final String INTENT_EXTRA_NAME_REFRESH = "subsonic.refresh";
4747 public static final String INTENT_EXTRA_LASTFM_APP_NAME = "app-name";
48 public static final String INTENT_EXTRA_LASTFM_APP_PACKAGE = "app-package";
49 public static final String INTENT_EXTRA_LASTFM_TRACK = "track";
50 public static final String INTENT_EXTRA_LASTFM_ARTIST = "artist";
51 public static final String INTENT_EXTRA_LASTFM_ALBUM = "album";
52 public static final String INTENT_EXTRA_LASTFM_PLAYER = "player";
53 public static final String INTENT_EXTRA_LASTFM_DURATION = "duration";
54 public static final String INTENT_EXTRA_LASTFM_STATE = "state";
55
56 // Names for external intents
57 public static final String INTENT_SCROBBLE_LASTFM = "com.adam.aslfms.notify.playstatechanged";
58
59 // Last.fm scrobbling values
60 public static final String LASTFM_APP_NAME = "Ubuntu One Music";
61 public static final String LASTFM_APP_PACKAGE = "net.sourceforge.subsonic.androidapp";
62 public static final int LASTFM_STATE_START = 0;
63 public static final int LASTFM_STATE_RESUME = 1;
64 public static final int LASTFM_STATE_PAUSE = 2;
65 public static final int LASTFM_STATE_COMPLETE = 3;
4866
49 // Notification IDs.67 // Notification IDs.
50 public static final int NOTIFICATION_ID_PLAYING = 100;68 public static final int NOTIFICATION_ID_PLAYING = 100;
@@ -62,6 +80,7 @@
62 public static final String PREFERENCES_KEY_MAX_BITRATE_MOBILE = "maxBitrateMobile";80 public static final String PREFERENCES_KEY_MAX_BITRATE_MOBILE = "maxBitrateMobile";
63 public static final String PREFERENCES_KEY_CACHE_SIZE = "cacheSize";81 public static final String PREFERENCES_KEY_CACHE_SIZE = "cacheSize";
64 public static final String PREFERENCES_KEY_PRELOAD_COUNT = "preloadCount";82 public static final String PREFERENCES_KEY_PRELOAD_COUNT = "preloadCount";
83 public static final String PREFERENCES_KEY_LASTFM_SCROBBLING = "lastfmScrobbling";
6584
66 // Name of the preferences file.85 // Name of the preferences file.
67 public static final String PREFERENCES_FILE_NAME = "net.sourceforge.subsonic.u1m_preferences";86 public static final String PREFERENCES_FILE_NAME = "net.sourceforge.subsonic.u1m_preferences";

Subscribers

People subscribed via source and target branches

to status/vote changes: