public static final String MUSIC_ONLY_SELECTION = MediaStore.Audio.AudioColumns.IS_MUSIC + "=1"
+ " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"; //$NON-NLS-2$
- private static boolean sShakeToPlayEnabled;
+ public static final long UPDATE_FREQUENCY_MS = 500;
+ public static final long UPDATE_FREQUENCY_FAST_MS = 30;
static {
mConnectionMap = new WeakHashMap<Context, ServiceBinder>();
if (realActivity == null) {
realActivity = (Activity)context;
}
- sShakeToPlayEnabled = PreferenceUtils.getInstance(context).getShakeToPlay();
final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
contextWrapper.startService(new Intent(contextWrapper, MusicPlaybackService.class));
- final ServiceBinder binder = new ServiceBinder(callback);
+ final ServiceBinder binder = new ServiceBinder(callback,
+ contextWrapper.getApplicationContext());
if (contextWrapper.bindService(
new Intent().setClass(contextWrapper, MusicPlaybackService.class), binder, 0)) {
mConnectionMap.put(contextWrapper, binder);
public static final class ServiceBinder implements ServiceConnection {
private final ServiceConnection mCallback;
+ private final Context mContext;
/**
* Constructor of <code>ServiceBinder</code>
*
* @param context The {@link ServiceConnection} to use
*/
- public ServiceBinder(final ServiceConnection callback) {
+ public ServiceBinder(final ServiceConnection callback, final Context context) {
mCallback = callback;
+ mContext = context;
}
@Override
if (mCallback != null) {
mCallback.onServiceConnected(className, service);
}
- MusicUtils.setShakeToPlayEnabled(sShakeToPlayEnabled);
+ MusicUtils.initPlaybackServiceWithSettings(mContext);
}
@Override
}
/**
+ * Initialize playback service with values from Settings
+ */
+ public static void initPlaybackServiceWithSettings(final Context context) {
+ MusicUtils.setShakeToPlayEnabled(
+ PreferenceUtils.getInstance(context).getShakeToPlay());
+ MusicUtils.setShowAlbumArtOnLockscreen(
+ PreferenceUtils.getInstance(context).getShowAlbumArtOnLockscreen());
+ }
+
+ /**
* Set shake to play status
*/
- public static void setShakeToPlayEnabled(boolean enabled) {
+ public static void setShakeToPlayEnabled(final boolean enabled) {
try {
if (mService != null) {
mService.setShakeToPlayEnabled(enabled);
}
/**
+ * Set show album art on lockscreen
+ */
+ public static void setShowAlbumArtOnLockscreen(final boolean enabled) {
+ try {
+ if (mService != null) {
+ mService.setLockscreenAlbumArt(enabled);
+ }
+ } catch (final RemoteException ignored) {
+ }
+ }
+
+ /**
* Changes to the next track asynchronously
*/
public static void asyncNext(final Context context) {
if (forceShuffle) {
mService.setShuffleMode(MusicPlaybackService.SHUFFLE_NORMAL);
}
- final long currentId = mService.getAudioId();
- final int currentQueuePosition = getQueuePosition();
- if (position != -1 && currentQueuePosition == position && currentId == list[position]) {
- final long[] playlist = getQueue();
- if (Arrays.equals(list, playlist)) {
- mService.play();
- return;
- }
- }
if (position < 0) {
position = 0;
}