Permalink
Browse files

Updated BuiltInMusicAppReceiver to support Neutron Music Player, as s…

…uggested by Dmitry Kostjuchenko
  • Loading branch information...
1 parent c7cb39d commit c172176136fd80bf234c8a75685f898fabf1cb57 @tgwizard committed Apr 20, 2012
Showing with 57 additions and 28 deletions.
  1. +57 −28 src/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java
@@ -40,7 +40,8 @@
* @author tgwizard
* @since 1.2.7
*/
-public abstract class BuiltInMusicAppReceiver extends AbstractPlayStatusReceiver {
+public abstract class BuiltInMusicAppReceiver extends
+ AbstractPlayStatusReceiver {
private static final String TAG = "SLSBuiltInMusicAppReceiver";
@@ -51,17 +52,18 @@
final String app_package;
final String app_name;
- public BuiltInMusicAppReceiver(String stopAction, String appPackage, String appName) {
+ public BuiltInMusicAppReceiver(String stopAction, String appPackage,
+ String appName) {
super();
stop_action = stopAction;
app_package = appPackage;
app_name = appName;
}
@Override
- protected void parseIntent(Context ctx, String action, Bundle bundle) throws IllegalArgumentException {
-
- MusicAPI musicAPI = MusicAPI.fromReceiver(ctx, app_name, app_package, null, true);
+ protected void parseIntent(Context ctx, String action, Bundle bundle)
+ throws IllegalArgumentException {
+ MusicAPI musicAPI = getMusicAPI(ctx, bundle);
setMusicAPI(musicAPI);
Track.Builder b = new Track.Builder();
@@ -80,6 +82,26 @@ protected void parseIntent(Context ctx, String action, Bundle bundle) throws Ill
setTrack(b.build());
}
+ MusicAPI getMusicAPI(Context ctx, Bundle bundle) {
+ CharSequence bundleAppName = bundle.getCharSequence("player");
+ CharSequence bundleAppPackage = bundle.getCharSequence("package");
+
+ MusicAPI musicAPI;
+ if ((bundleAppName != null) && (bundleAppPackage != null)) {
+ Log.d(
+ TAG,
+ String.format(
+ "Will load MusicAPI from bundle: [appName: %s, appPackage: %s]",
+ bundleAppName, bundleAppPackage));
+ musicAPI = MusicAPI.fromReceiver(ctx, bundleAppName.toString(),
+ bundleAppPackage.toString(), null, true);
+ } else {
+ musicAPI = MusicAPI.fromReceiver(ctx, app_name, app_package, null,
+ true);
+ }
+ return musicAPI;
+ }
+
void parseTrack(Context ctx, Track.Builder b, Bundle bundle) {
long audioid = getAudioId(bundle);
@@ -90,20 +112,44 @@ void parseTrack(Context ctx, Track.Builder b, Bundle bundle) {
}
}
+ long getAudioId(Bundle bundle) {
+ long id = NO_AUDIO_ID;
+ Object idBundle = bundle.get("id");
+ if (idBundle != null) {
+ if (idBundle instanceof Long)
+ id = (Long) idBundle;
+ else if (idBundle instanceof Integer)
+ id = (Integer) idBundle;
+ else if (idBundle instanceof String) {
+ id = Long.valueOf((String) idBundle).longValue();
+ } else {
+ Log.w(TAG,
+ "Got unsupported idBundle type: " + idBundle.getClass());
+ }
+ }
+ return id;
+ }
+
boolean shouldFetchFromMediaStore(Context ctx, long audioid) {
- return audioid != NO_AUDIO_ID;
+ if (audioid > 0)
+ return true;
+ return false;
}
void readTrackFromMediaStore(Context ctx, Track.Builder b, long audioid) {
Log.d(TAG, "Will read data from mediastore");
- final String[] columns = new String[] { MediaStore.Audio.AudioColumns.ARTIST,
- MediaStore.Audio.AudioColumns.TITLE, MediaStore.Audio.AudioColumns.DURATION,
- MediaStore.Audio.AudioColumns.ALBUM, MediaStore.Audio.AudioColumns.TRACK, };
+ final String[] columns = new String[] {
+ MediaStore.Audio.AudioColumns.ARTIST,
+ MediaStore.Audio.AudioColumns.TITLE,
+ MediaStore.Audio.AudioColumns.DURATION,
+ MediaStore.Audio.AudioColumns.ALBUM,
+ MediaStore.Audio.AudioColumns.TRACK, };
Cursor cur = ctx.getContentResolver().query(
- ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioid), columns, null, null,
- null);
+ ContentUris.withAppendedId(
+ MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioid), columns,
+ null, null, null);
if (cur == null) {
throw new IllegalArgumentException("could not open cursor to media in media store");
@@ -152,21 +198,4 @@ void readTrackFromBundleData(Track.Builder b, Bundle bundle) {
b.setAlbum(al.toString());
b.setTrack(tr.toString());
}
-
- long getAudioId(Bundle bundle) {
- long id = NO_AUDIO_ID;
- Object idBundle = bundle.get("id");
- if (idBundle != null) {
- if (idBundle instanceof Long)
- id = (Long) idBundle;
- else if (idBundle instanceof Integer)
- id = (Integer) idBundle;
- else if (idBundle instanceof String) {
- id = Long.valueOf((String) idBundle).longValue();
- } else {
- Log.w(TAG, "Got unsupported idBundle type: " + idBundle.getClass());
- }
- }
- return id;
- }
}

0 comments on commit c172176

Please sign in to comment.