aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java4
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java5
2 files changed, 6 insertions, 3 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index b1b4c01b..1f89ea4b 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -478,7 +478,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
this.currentPlaying = currentPlaying;
if (currentPlaying != null) {
- Util.requestAudioFocus(this);
Util.broadcastNewTrackInfo(this, currentPlaying.getSong());
currentPlaying.setPlaying(true);
mRemoteControl.updateMetadata(this, currentPlaying.getSong());
@@ -728,13 +727,14 @@ public class DownloadServiceImpl extends Service implements DownloadService {
Util.broadcastPlaybackStatusChange(this, playerState);
this.playerState = playerState;
- mRemoteControl.setPlaybackState(playerState.getRemoteControlClientPlayState());
if (show) {
+ Util.requestAudioFocus(this);
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
} else if (hide) {
Util.hidePlayingNotification(this, this, handler);
}
+ mRemoteControl.setPlaybackState(playerState.getRemoteControlClientPlayState());
if (playerState == STARTED) {
scrobbler.scrobble(this, currentPlaying, false);
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index fd6a9b6d..015cffe9 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -102,6 +102,7 @@ public final class Util {
public static final String AVRCP_PLAYSTATE_CHANGED = "com.android.music.playstatechanged";
public static final String AVRCP_METADATA_CHANGED = "com.android.music.metachanged";
+ private static boolean hasFocus = false;
private static boolean pauseFocus = false;
private static boolean lowerFocus = false;
@@ -781,8 +782,9 @@ public final class Util {
@TargetApi(8)
public static void requestAudioFocus(final Context context) {
- if (Build.VERSION.SDK_INT >= 8) {
+ if (Build.VERSION.SDK_INT >= 8 && !hasFocus) {
final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ hasFocus = true;
audioManager.requestAudioFocus(new OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
DownloadServiceImpl downloadService = (DownloadServiceImpl)context;
@@ -807,6 +809,7 @@ public final class Util {
downloadService.setVolume(1.0f);
}
} else if(focusChange == AudioManager.AUDIOFOCUS_LOSS) {
+ hasFocus = false;
downloadService.pause();
}
}