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 #111 from jadkik/master
Browse files Browse the repository at this point in the history
Add support for the newer Sony Xperia/Sony Ericsson Walkman app
  • Loading branch information
tgwizard committed Feb 12, 2014
2 parents bd97b26 + 61ccb13 commit 5150ebc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions AndroidManifest.xml
Expand Up @@ -144,6 +144,10 @@
<action android:name="com.sonyericsson.music.metachanged" />
<action android:name="com.sonyericsson.music.playbackcomplete" />
<action android:name="com.sonyericsson.music.playstatechanged" />

<!-- from https://github.com/Ambroos/Xperia-Scrobbler-2013-Compatibility/ -->
<action android:name="com.sonyericsson.music.playbackcontrol.ACTION_TRACK_STARTED" />
<action android:name="com.sonyericsson.music.playbackcontrol.ACTION_PAUSED" />
</intent-filter>
</receiver>

Expand Down
14 changes: 13 additions & 1 deletion src/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java
Expand Up @@ -59,6 +59,18 @@ public BuiltInMusicAppReceiver(String stopAction, String appPackage,
app_package = appPackage;
app_name = appName;
}

/**
* Depending on the action received decide whether it should signal a stop or not.
* By default, it compares it to the unique `this.stop_action`, but there might be
* multiple actions that cause a stop signal.
*
* @param action the received action
* @return true when the received action is a stop action, false otherwise
*/
protected boolean isStopAction(String action) {
return action.equals(stop_action);
}

@Override
protected void parseIntent(Context ctx, String action, Bundle bundle)
Expand All @@ -72,7 +84,7 @@ protected void parseIntent(Context ctx, String action, Bundle bundle)

parseTrack(ctx, b, bundle);

if (action.equals(stop_action)) {
if (isStopAction(action)) {
setState(Track.State.PLAYLIST_FINISHED);
} else {
setState(Track.State.RESUME);
Expand Down
16 changes: 15 additions & 1 deletion src/com/adam/aslfms/receiver/SEMCMusicReceiver.java
Expand Up @@ -9,12 +9,26 @@
public class SEMCMusicReceiver extends BuiltInMusicAppReceiver {

static final String APP_PACKAGE = "com.sonyericsson.music";
static final String ACTION_SEMC_STOP = "com.sonyericsson.music.playbackcontrol.ACTION_PLAYBACK_PAUSE";
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";

public SEMCMusicReceiver() {
super(ACTION_SEMC_STOP, APP_PACKAGE, "Sony Ericsson Music Player");
}

@Override
/**
* Checks that the action received is either the one used in the
* newer Sony Xperia devices or that of the previous versions
* of the app.
*
* @param action the received action
* @return true when the received action is a stop action, false otherwise
*/
protected boolean isStopAction(String action) {
return action.equals(ACTION_SEMC_STOP) || action.equals(ACTION_SEMC_STOP_LEGACY);
}

@Override
protected void parseIntent(Context ctx, String action, Bundle bundle) throws IllegalArgumentException {
Expand Down

0 comments on commit 5150ebc

Please sign in to comment.