aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-11-12 09:54:22 -0800
committerScott Jackson <daneren2005@gmail.com>2012-11-12 09:54:22 -0800
commit3a64650fa51b5caf330bcd8b0fa6d8e514397e6f (patch)
tree8f5e25ba292c34e1683db602f5ca63eb77df98de /subsonic-android
parent4e4dc1bb43066da355da90c1f2c220a9b4e56e23 (diff)
downloaddsub-3a64650fa51b5caf330bcd8b0fa6d8e514397e6f.tar.gz
dsub-3a64650fa51b5caf330bcd8b0fa6d8e514397e6f.tar.bz2
dsub-3a64650fa51b5caf330bcd8b0fa6d8e514397e6f.zip
Added option to either pause or lower volume on transient loss of audio focus
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/res/values/arrays.xml11
-rw-r--r--subsonic-android/res/values/strings.xml4
-rw-r--r--subsonic-android/res/xml/settings.xml7
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java3
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java22
6 files changed, 44 insertions, 4 deletions
diff --git a/subsonic-android/res/values/arrays.xml b/subsonic-android/res/values/arrays.xml
index 0ebb02bd..dcec441f 100644
--- a/subsonic-android/res/values/arrays.xml
+++ b/subsonic-android/res/values/arrays.xml
@@ -91,5 +91,16 @@
<item>@string/settings.network_timeout_45000</item>
<item>@string/settings.network_timeout_60000</item>
</string-array>
+
+ <string-array name="tempLossValues">
+ <item>0</item>
+ <item>2</item>
+ <item>4</item>
+ </string-array>
+ <string-array name="tempLossNames">
+ <item>@string/settings.temp_loss_pause</item>
+ <item>@string/settings.temp_loss_half</item>
+ <item>@string/settings.temp_loss_fourth</item>
+ </string-array>
</resources> \ No newline at end of file
diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml
index 61c705ba..074d9686 100644
--- a/subsonic-android/res/values/strings.xml
+++ b/subsonic-android/res/values/strings.xml
@@ -225,6 +225,10 @@
<string name="settings.sleep_timer_off">Off</string>
<string name="settings.sleep_timer_on">On</string>
<string name="settings.sleep_timer_always_on">Always On</string>
+ <string name="settings.temp_loss_title">Temperary Loss of Focus</string>
+ <string name="settings.temp_loss_pause">Pause Playback</string>
+ <string name="settings.temp_loss_half">Half volume</string>
+ <string name="settings.temp_loss_fourth">Fourth Volume</string>
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
diff --git a/subsonic-android/res/xml/settings.xml b/subsonic-android/res/xml/settings.xml
index 294f7601..f79063cc 100644
--- a/subsonic-android/res/xml/settings.xml
+++ b/subsonic-android/res/xml/settings.xml
@@ -161,6 +161,13 @@
android:key="sleepTimerDuration"
android:defaultValue="60"
android:digits="0123456789"/>
+
+ <ListPreference
+ android:title="@string/settings.temp_loss_title"
+ android:key="tempLoss"
+ android:defaultValue="0"
+ android:entryValues="@array/tempLossValues"
+ android:entries="@array/tempLossNames"/>
</PreferenceCategory>
<PreferenceCategory
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
index febfedca..82b3cc05 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SettingsActivity.java
@@ -58,6 +58,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private ListPreference preloadCount;
private EditTextPreference randomSize;
private EditTextPreference sleepTimerDuration;
+ private ListPreference tempLoss;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -73,6 +74,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT);
randomSize = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_RANDOM_SIZE);
sleepTimerDuration = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION);
+ tempLoss = (ListPreference) findPreference(Constants.PREFERENCES_KEY_TEMP_LOSS);
findPreference("testConnection1").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
@@ -161,6 +163,7 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
preloadCount.setSummary(preloadCount.getEntry());
randomSize.setSummary(randomSize.getText());
sleepTimerDuration.setSummary(sleepTimerDuration.getText());
+ tempLoss.setSummary(tempLoss.getEntry());
for (ServerSettings ss : serverSettings.values()) {
ss.update();
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
index 2d67d3c9..eb0a15fd 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java
@@ -79,6 +79,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_SLEEP_TIMER = "sleepTimer";
public static final String PREFERENCES_KEY_SLEEP_TIMER_DURATION = "sleepTimerDuration";
public static final String PREFERENCES_KEY_OFFLINE = "offline";
+ public static final String PREFERENCES_KEY_TEMP_LOSS = "tempLoss";
// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences";
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index b6ad69bb..53bc54c4 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -99,6 +99,8 @@ public final class Util {
public static final String EVENT_PLAYSTATE_CHANGED = "github.daneren2005.dsub.EVENT_PLAYSTATE_CHANGED";
private static boolean pauseFocus = false;
+ private static int currentVolume = 0;
+ private static int lossPref = 0;
private static final Map<Integer, Version> SERVER_REST_VERSIONS = new ConcurrentHashMap<Integer, Version>();
@@ -746,20 +748,32 @@ public final class Util {
@TargetApi(8)
public static void requestAudioFocus(final Context context) {
- if (Build.VERSION.SDK_INT >= 8) {
- AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+ if (Build.VERSION.SDK_INT >= 8) {
+ final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(new OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
DownloadServiceImpl downloadService = (DownloadServiceImpl)context;
if(focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
if(downloadService.getPlayerState() == PlayerState.STARTED) {
pauseFocus = true;
- downloadService.pause();
+
+ SharedPreferences prefs = getPreferences(context);
+ lossPref = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_TEMP_LOSS, "0"));
+ if(lossPref > 0) {
+ currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+ audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int)Math.ceil(currentVolume / (double)lossPref), 0);
+ } else {
+ downloadService.pause();
+ }
}
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
if(pauseFocus) {
pauseFocus = false;
- downloadService.start();
+ if(lossPref > 0) {
+ audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, 0);
+ } else {
+ downloadService.start();
+ }
}
}
}