Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #191 from tgwizard/testing-149
Browse files Browse the repository at this point in the history
  • Loading branch information
HumbleBeeBumbleBee authored and HumbleBeeBumbleBee committed May 3, 2015
2 parents 8f67005 + d94b634 commit a05c687
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/com/adam/aslfms/receiver/AmazonMP3Receiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AmazonMP3Receiver extends AbstractPlayStatusReceiver {
static final String APP_PACKAGE = "com.amazon.mp3";
static final String APP_NAME = "Amazon Music";

static final String ACTION_AMZN_META = "com.amazon.mp3.metachanged";
static final String ACTION_AMZN_METACHANGED = "com.amazon.mp3.metachanged";
static final String ACTION_AMZN_PLAYSTATE = "com.amazon.mp3.playstatechanged";

static final String TAG = "AmazonMP3Receiver";
Expand All @@ -46,7 +46,7 @@ protected void parseIntent(Context ctx, String action, Bundle bundle) {
ctx, APP_NAME, APP_PACKAGE, null, false);
setMusicAPI(musicAPI);

if (action == ACTION_AMZN_PLAYSTATE)
if (action.equals(ACTION_AMZN_PLAYSTATE))
{
setTrack(track);
int state = bundle.getInt("com.amazon.mp3.playstate");
Expand All @@ -67,7 +67,7 @@ else if (state == 3) {
Log.d(TAG,"Setting state to RESUME");
}
}
else if (action == ACTION_AMZN_META)
else if (action.equals(ACTION_AMZN_METACHANGED))
{
Track.Builder b = new Track.Builder();
b.setMusicAPI(musicAPI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public AndroidMusicJRTStudioBuildReceiver() {
super(ACTION_ANDROID_STOP, PACKAGE_NAME, NAME);
}

@Override
protected String getMetaChangedAction() {
return ACTION_ANDROID_METACHANGED;
}

@Override
boolean shouldFetchFromMediaStore(Context ctx, long audioid) {
if (Util.checkForInstalledApp(ctx, PACKAGE_NAME))
Expand Down
5 changes: 5 additions & 0 deletions src/com/adam/aslfms/receiver/AndroidMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public AndroidMusicReceiver() {
super(ACTION_ANDROID_STOP, PACKAGE_NAME, NAME);
}

@Override
protected String getMetaChangedAction() {
return ACTION_ANDROID_METACHANGED;
}

@Override
boolean shouldFetchFromMediaStore(Context ctx, long audioid) {
if (Util.checkForInstalledApp(ctx, GOOGLE_MUSIC_PACKAGE))
Expand Down
19 changes: 19 additions & 0 deletions src/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ protected boolean isStopAction(String action) {
return action.equals(stop_action);
}

/**
* Checks if action is the switching of the musical track.
* Keep in mind that when the track is ended and same track starts again
* (by looping for example) it is also a 'changed' condition.
* @param action
* @return
*/
protected boolean isChangedAction(String action) {
return action.equals(getMetaChangedAction());
}

/**
* Returns 'metachanged' intent action string for concrete application.
* @return concrete 'metachanged' intent
*/
protected abstract String getMetaChangedAction();

@Override
protected void parseIntent(Context ctx, String action, Bundle bundle)
throws IllegalArgumentException {
Expand All @@ -86,6 +103,8 @@ protected void parseIntent(Context ctx, String action, Bundle bundle)

if (isStopAction(action)) {
setState(Track.State.PLAYLIST_FINISHED);
} else if (isChangedAction(action)) {
setState(Track.State.CHANGED);
} else {
setState(Track.State.RESUME);
}
Expand Down
5 changes: 5 additions & 0 deletions src/com/adam/aslfms/receiver/HeroMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public class HeroMusicReceiver extends BuiltInMusicAppReceiver {
public HeroMusicReceiver() {
super(ACTION_HTC_STOP, "com.htc.music", "Hero Music Player");
}

@Override
protected String getMetaChangedAction() {
return ACTION_HTC_METACHANGED;
}
}
6 changes: 3 additions & 3 deletions src/com/adam/aslfms/receiver/LastFmAPIReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class LastFmAPIReceiver extends AbstractPlayStatusReceiver {

public static final String ACTION_LASTFMAPI_START = "fm.last.android.metachanged";
public static final String ACTION_LASTFMAPI_METACHANGED = "fm.last.android.metachanged";
public static final String ACTION_LASTFMAPI_PAUSERESUME = "fm.last.android.playbackpaused";
public static final String ACTION_LASTFMAPI_STOP = "fm.last.android.playbackcomplete";

Expand All @@ -49,8 +49,8 @@ protected void parseIntent(Context ctx, String action, Bundle bundle) throws Ill
"Apps using the Last.fm Android App API", false);
setMusicAPI(musicAPI);

if (action.equals(ACTION_LASTFMAPI_START)) {
setState(Track.State.START);
if (action.equals(ACTION_LASTFMAPI_METACHANGED)) {
setState(Track.State.CHANGED);
Track.Builder b = new Track.Builder();
b.setMusicAPI(musicAPI);
b.setWhen(Util.currentTimeSecsUTC());
Expand Down
12 changes: 6 additions & 6 deletions src/com/adam/aslfms/receiver/LgOptimus4xReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class LgOptimus4xReceiver extends AbstractPlayStatusReceiver {
static final String APP_PACKAGE = "com.lge.music";
static final String APP_NAME = "LG Music Player";

static final String ACTION_LGE_START = "com.lge.music.metachanged";
static final String ACTION_LGE_METACHANGED = "com.lge.music.metachanged";
static final String ACTION_LGE_PAUSERESUME = "com.lge.music.playstatechanged";
static final String ACTION_LGE_STOP = "com.lge.music.endofplayback";

Expand All @@ -52,18 +52,18 @@ protected void parseIntent(Context ctx, String action, Bundle bundle) {
ctx, APP_NAME, APP_PACKAGE, null, false);
setMusicAPI(musicAPI);

if (action == ACTION_LGE_STOP) {
if (action.equals(ACTION_LGE_STOP)) {
setState(Track.State.COMPLETE);
setTrack(Track.SAME_AS_CURRENT);
Log.d(TAG,"Setting state to COMPLETE");
return;
}

if (action == ACTION_LGE_START) {
setState(Track.State.START);
Log.d(TAG,"Setting state to START");
if (action.equals(ACTION_LGE_METACHANGED)) {
setState(Track.State.CHANGED);
Log.d(TAG,"Setting state to CHANGED");
}
else if (action == ACTION_LGE_PAUSERESUME) {
else if (action.equals(ACTION_LGE_PAUSERESUME)) {
boolean playing = bundle.getBoolean("playing");
Track.State state =
(playing) ? (Track.State.RESUME) : (Track.State.PAUSE);
Expand Down
6 changes: 6 additions & 0 deletions src/com/adam/aslfms/receiver/MIUIMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ public class MIUIMusicReceiver extends BuiltInMusicAppReceiver {

static final String APP_PACKAGE = "com.miui.player";
static final String ACTION_MIUI_STOP = "com.miui.player.playbackcomplete";
static final String ACTION_MIUI_METACHANGED = "com.miui.player.metachanged";

public MIUIMusicReceiver() {
super(ACTION_MIUI_STOP, APP_PACKAGE, "MIUI Music Player");
}

@Override
protected String getMetaChangedAction() {
return ACTION_MIUI_METACHANGED;
}

@Override
protected void parseIntent(Context ctx, String action, Bundle bundle) throws IllegalArgumentException {
super.parseIntent(ctx, action, bundle);
Expand Down
5 changes: 5 additions & 0 deletions src/com/adam/aslfms/receiver/MyTouch4GMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public class MyTouch4GMusicReceiver extends BuiltInMusicAppReceiver {
public MyTouch4GMusicReceiver() {
super(ACTION_MYTOUCH4G_STOP, "com.real.IMP", "myTouch 4G Music Player");
}

@Override
protected String getMetaChangedAction() {
return ACTION_MYTOUCH4G_METACHANGED;
}
}
5 changes: 5 additions & 0 deletions src/com/adam/aslfms/receiver/PlayerProReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public class PlayerProReceiver extends BuiltInMusicAppReceiver {
public PlayerProReceiver() {
super(ACTION_PLAYER_PRO_STOP, "com.tbig.playerpro", "Player Pro");
}

@Override
protected String getMetaChangedAction() {
return ACTION_PLAYER_PRO_METACHANGED;
}
}
5 changes: 5 additions & 0 deletions src/com/adam/aslfms/receiver/PlayerProTrialReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public class PlayerProTrialReceiver extends BuiltInMusicAppReceiver {
public PlayerProTrialReceiver() {
super(ACTION_PLAYER_PRO_TRIAL_STOP, "com.tbig.playerprotrial", "Player Pro Trial");
}

@Override
protected String getMetaChangedAction() {
return ACTION_PLAYER_PRO_TRIAL_METACHANGED;
}
}
9 changes: 8 additions & 1 deletion src/com/adam/aslfms/receiver/SEMCMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

public class SEMCMusicReceiver extends BuiltInMusicAppReceiver {

private static final String TAG = "SEMCMusicReceiver";

static final String APP_PACKAGE = "com.sonyericsson.music";
static final String ACTION_SEMC_STOP_LEGACY = "com.sonyericsson.music.playbackcontrol.ACTION_PLAYBACK_PAUSE";
static final String ACTION_SEMC_STOP = "com.sonyericsson.music.playbackcontrol.ACTION_PAUSED";
private static final String TAG = "SEMCMusicReceiver";
static final String ACTION_SEMC_METACHANGED = "com.sonyericsson.music.metachanged";

public SEMCMusicReceiver() {
super(ACTION_SEMC_STOP, APP_PACKAGE, "Sony Ericsson Music Player");
Expand All @@ -30,6 +32,11 @@ protected boolean isStopAction(String action) {
return action.equals(ACTION_SEMC_STOP) || action.equals(ACTION_SEMC_STOP_LEGACY);
}

@Override
protected String getMetaChangedAction() {
return ACTION_SEMC_METACHANGED;
}

@Override
protected void parseIntent(Context ctx, String action, Bundle bundle) throws IllegalArgumentException {
super.parseIntent(ctx, action, bundle);
Expand Down
5 changes: 5 additions & 0 deletions src/com/adam/aslfms/receiver/SamsungMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public SamsungMusicReceiver() {
super(ACTION_SAMSUNG_STOP, "com.samsung.sec.android.MusicPlayer",
"Samsung Music Player");
}

@Override
protected String getMetaChangedAction() {
return ACTION_SAMSUNG_METACHANGED;
}
}
6 changes: 5 additions & 1 deletion src/com/adam/aslfms/receiver/WinampMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class WinampMusicReceiver extends BuiltInMusicAppReceiver {
@SuppressWarnings("unused")
private static final String TAG = "SLSWinampReceiver";

public static final String ACTION_WINAMP_START = "com.nullsoft.winamp.metachanged";
public static final String ACTION_WINAMP_METACHANED = "com.nullsoft.winamp.metachanged";
public static final String ACTION_WINAMP_PAUSERESUME = "com.nullsoft.winamp.playstatechanged";
// doesn't seem to work
public static final String ACTION_WINAMP_STOP = "com.nullsoft.winamp.playbackcomplete";
Expand All @@ -40,4 +40,8 @@ public WinampMusicReceiver() {
super(ACTION_WINAMP_STOP, "com.nullsoft.winamp", "Winamp");
}

@Override
protected String getMetaChangedAction() {
return ACTION_WINAMP_METACHANED;
}
}
10 changes: 10 additions & 0 deletions src/com/adam/aslfms/service/ScrobblingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ private synchronized void onPlayStateChanged(Track track, Track.State state) {
tryQueue(mCurrentTrack);
}
}
// implemented as a combination of COMPLETE -> START state handlers.
} else if (state == Track.State.CHANGED) {
if (mCurrentTrack != null) {
mCurrentTrack.updateTimePlayed();
tryQueue(mCurrentTrack);
tryScrobble();
}
mCurrentTrack = track;
mCurrentTrack.updateTimePlayed();
tryNotifyNP(mCurrentTrack);
} else if (state == Track.State.COMPLETE) { // "complete"
// TODO test this state
if (mCurrentTrack == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/adam/aslfms/util/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Track {

// TODO: move me
public enum State {
START, RESUME, PAUSE, COMPLETE, PLAYLIST_FINISHED, UNKNOWN_NONPLAYING
START, RESUME, PAUSE, CHANGED, COMPLETE, PLAYLIST_FINISHED, UNKNOWN_NONPLAYING
};

/**
Expand Down

0 comments on commit a05c687

Please sign in to comment.