aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-09-04 12:39:06 -0700
committerScott Jackson <daneren2005@gmail.com>2012-09-04 12:39:06 -0700
commit3b321a0a40e6b4707b5a55c167c1023f77911aa2 (patch)
treef449e5e9a1184e493b168e0d6da96a4121bdbd5e
parentf9fcaefd307d0cd7dcd4401f5f264d3566166a03 (diff)
downloaddsub-3b321a0a40e6b4707b5a55c167c1023f77911aa2.tar.gz
dsub-3b321a0a40e6b4707b5a55c167c1023f77911aa2.tar.bz2
dsub-3b321a0a40e6b4707b5a55c167c1023f77911aa2.zip
Fixes #15
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java109
1 files changed, 52 insertions, 57 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index bce1cca8..9ccb67a4 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -138,64 +138,59 @@ public class DownloadServiceImpl extends Service implements DownloadService {
return false;
}
});
-
-// try {
-// Class.forName("android.media.RemoteControlClient");
- if (Build.VERSION.SDK_INT >= 14) {
-
- Util.requestAudioFocus(this);
- Util.registerMediaButtonEventReceiver(this);
-
- // Use the remote control APIs (if available) to set the playback state
- if (mRemoteControlClient == null) {
- AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- ComponentName mediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
-// audioManager.registerMediaButtonEventReceiver(mediaButtonReceiverComponent);
- // build the PendingIntent for the remote control client
- Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
- mediaButtonIntent.setComponent(mediaButtonReceiverComponent);
- PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0);
- // create and register the remote control client
- mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
- audioManager.registerRemoteControlClient(mRemoteControlClient);
- }
-
- mRemoteControlClient.setPlaybackState(
- RemoteControlClient.PLAYSTATE_STOPPED);
-
- mRemoteControlClient.setTransportControlFlags(
- RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
- RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
- RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
- RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
- RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
- RemoteControlClient.FLAG_KEY_MEDIA_STOP);
- }
-// } catch (ClassNotFoundException x) {
-// // Ignored.
-// }
-
- if (equalizerAvailable) {
- equalizerController = new EqualizerController(this, mediaPlayer);
- if (!equalizerController.isAvailable()) {
- equalizerController = null;
- } else {
- equalizerController.loadSettings();
- }
- }
- if (visualizerAvailable) {
- visualizerController = new VisualizerController(this, mediaPlayer);
- if (!visualizerController.isAvailable()) {
- visualizerController = null;
- }
- }
- PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
- wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
- wakeLock.setReferenceCounted(false);
+ if (Build.VERSION.SDK_INT >= 14) {
+
+ Util.requestAudioFocus(this);
+ Util.registerMediaButtonEventReceiver(this);
+
+ // Use the remote control APIs (if available) to set the playback state
+ if (mRemoteControlClient == null) {
+ AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ ComponentName mediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
+ // audioManager.registerMediaButtonEventReceiver(mediaButtonReceiverComponent);
+ // build the PendingIntent for the remote control client
+ Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
+ mediaButtonIntent.setComponent(mediaButtonReceiverComponent);
+ PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0);
+ // create and register the remote control client
+ mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
+ audioManager.registerRemoteControlClient(mRemoteControlClient);
+ }
+
+ mRemoteControlClient.setPlaybackState(
+ RemoteControlClient.PLAYSTATE_STOPPED);
+
+ mRemoteControlClient.setTransportControlFlags(
+ RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
+ RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
+ RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
+ RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
+ RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
+ RemoteControlClient.FLAG_KEY_MEDIA_STOP);
+ }
+
+ if (equalizerAvailable) {
+ equalizerController = new EqualizerController(this, mediaPlayer);
+ if (!equalizerController.isAvailable()) {
+ equalizerController = null;
+ } else {
+ equalizerController.loadSettings();
+ }
+ }
+ if (visualizerAvailable) {
+ visualizerController = new VisualizerController(this, mediaPlayer);
+ if (!visualizerController.isAvailable()) {
+ visualizerController = null;
+ }
+ }
+
+ PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
+ wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
+ wakeLock.setReferenceCounted(false);
- instance = this;
- lifecycleSupport.onCreate();
+ instance = this;
+ lifecycleSupport.onCreate();
}
@Override
@@ -697,7 +692,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
boolean show = this.playerState == PAUSED && playerState == PlayerState.STARTED;
- boolean hide = this.playerState == STARTED && playerState == PlayerState.PAUSED;
+ boolean hide = this.playerState == STARTED && (playerState == PlayerState.PAUSED || playerState == PlayerState.IDLE);
Util.broadcastPlaybackStatusChange(this, playerState);
this.playerState = playerState;