diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-01-01 21:49:01 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-01-01 21:49:01 -0800 |
commit | dc8afd5dbc1606be50b694c876c85df6eb57992d (patch) | |
tree | 852861d6b928c64b78decb7766b716d6bc42624e | |
parent | 8068fc7478741a41695fe063df54990e595ff35d (diff) | |
download | dsub-dc8afd5dbc1606be50b694c876c85df6eb57992d.tar.gz dsub-dc8afd5dbc1606be50b694c876c85df6eb57992d.tar.bz2 dsub-dc8afd5dbc1606be50b694c876c85df6eb57992d.zip |
Closes #63 Only request audio focus once instead of on every play
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 4 | ||||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/util/Util.java | 5 |
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(); } } |