aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-06-03 19:24:47 -0700
committerScott Jackson <daneren2005@gmail.com>2014-06-03 19:24:47 -0700
commit4879732b6e314d9cfa6a60de481a99495ca0c31a (patch)
treed90069240e17dc859a9421ca6bd0f5507f7f6ca0 /src
parent50acda0bab877f1dc0125c00abe7bad765da3a17 (diff)
downloaddsub-4879732b6e314d9cfa6a60de481a99495ca0c31a.tar.gz
dsub-4879732b6e314d9cfa6a60de481a99495ca0c31a.tar.bz2
dsub-4879732b6e314d9cfa6a60de481a99495ca0c31a.zip
Add another state PAUSED_TEMP, abandon focus in PAUSED
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/domain/PlayerState.java1
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java7
-rw-r--r--src/github/daneren2005/dsub/util/Util.java19
3 files changed, 20 insertions, 7 deletions
diff --git a/src/github/daneren2005/dsub/domain/PlayerState.java b/src/github/daneren2005/dsub/domain/PlayerState.java
index 2b63077b..21f1b1a4 100644
--- a/src/github/daneren2005/dsub/domain/PlayerState.java
+++ b/src/github/daneren2005/dsub/domain/PlayerState.java
@@ -32,6 +32,7 @@ public enum PlayerState {
STARTED(RemoteControlClient.PLAYSTATE_PLAYING),
STOPPED(RemoteControlClient.PLAYSTATE_STOPPED),
PAUSED(RemoteControlClient.PLAYSTATE_PAUSED),
+ PAUSED_TEMP(RemoteControlClient.PLAYSTATE_PAUSED),
COMPLETED(RemoteControlClient.PLAYSTATE_STOPPED);
private final int mRemoteControlClientPlayState;
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index cebc36e0..c1576fe2 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -23,6 +23,7 @@ import static github.daneren2005.dsub.domain.PlayerState.COMPLETED;
import static github.daneren2005.dsub.domain.PlayerState.DOWNLOADING;
import static github.daneren2005.dsub.domain.PlayerState.IDLE;
import static github.daneren2005.dsub.domain.PlayerState.PAUSED;
+import static github.daneren2005.dsub.domain.PlayerState.PAUSED_TEMP;
import static github.daneren2005.dsub.domain.PlayerState.PREPARED;
import static github.daneren2005.dsub.domain.PlayerState.PREPARING;
import static github.daneren2005.dsub.domain.PlayerState.STARTED;
@@ -913,6 +914,9 @@ public class DownloadService extends Service {
}
public synchronized void pause() {
+ pause(false);
+ }
+ public synchronized void pause(boolean temp) {
try {
if (playerState == STARTED) {
if (remoteState != RemoteControlState.LOCAL) {
@@ -920,7 +924,7 @@ public class DownloadService extends Service {
} else {
mediaPlayer.pause();
}
- setPlayerState(PAUSED);
+ setPlayerState(temp ? PAUSED_TEMP : PAUSED);
}
} catch (Exception x) {
handleError(x);
@@ -1048,6 +1052,7 @@ public class DownloadService extends Service {
} else {
Util.hidePlayingNotification(this, this, handler);
}
+ Util.abandonAudioFocus(this);
} else if(hide) {
Util.hidePlayingNotification(this, this, handler);
}
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index 91cca04b..b62b3382 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -109,7 +109,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 OnAudioFocusChangeListener focusListener;
private static boolean pauseFocus = false;
private static boolean lowerFocus = false;
@@ -1250,10 +1250,9 @@ public final class Util {
@TargetApi(8)
public static void requestAudioFocus(final Context context) {
- if (Build.VERSION.SDK_INT >= 8 && !hasFocus) {
+ if (Build.VERSION.SDK_INT >= 8 && focusListener == null) {
final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- hasFocus = true;
- audioManager.requestAudioFocus(new OnAudioFocusChangeListener() {
+ audioManager.requestAudioFocus(focusListener = new OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
DownloadService downloadService = (DownloadService)context;
if((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) && !downloadService.isRemoteEnabled()) {
@@ -1265,7 +1264,7 @@ public final class Util {
downloadService.setVolume(0.1f);
} else if(lossPref == 0 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT)) {
pauseFocus = true;
- downloadService.pause();
+ downloadService.pause(true);
}
}
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
@@ -1277,7 +1276,7 @@ public final class Util {
downloadService.setVolume(1.0f);
}
} else if(focusChange == AudioManager.AUDIOFOCUS_LOSS && !downloadService.isRemoteEnabled()) {
- hasFocus = false;
+ focusListener = null;
downloadService.pause();
audioManager.abandonAudioFocus(this);
}
@@ -1286,6 +1285,14 @@ public final class Util {
}
}
+ public static void abandonAudioFocus(Context context) {
+ if(focusListener != null) {
+ final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ audioManager.abandonAudioFocus(focusListener);
+ focusListener = null;
+ }
+ }
+
/**
* <p>Broadcasts the given song info as the new song being played.</p>
*/