Add a setting to control headset unplug detection

This commit is contained in:
Christopher Eby 2010-02-27 22:29:33 -06:00
parent cddfb03627
commit a857fad462
3 changed files with 16 additions and 8 deletions

View File

@ -16,6 +16,9 @@
<string name="headset_only_title">Disallow Use of Speaker</string> <string name="headset_only_title">Disallow Use of Speaker</string>
<string name="headset_only_summary">Do not play music when the speaker would be used</string> <string name="headset_only_summary">Do not play music when the speaker would be used</string>
<string name="headset_pause_title">Pause When Unplugged</string>
<string name="headset_pause_summary">Pause when the headphones are unplugged.</string>
<string name="remote_player_title">Use Remote Player</string> <string name="remote_player_title">Use Remote Player</string>
<string name="remote_player_summary_on">Clicking the notification will open a mini-player dialog</string> <string name="remote_player_summary_on">Clicking the notification will open a mini-player dialog</string>
<string name="remote_player_summary_off">Clicking the notification will open a the full player activity</string> <string name="remote_player_summary_off">Clicking the notification will open a the full player activity</string>

View File

@ -7,6 +7,11 @@
android:title="@string/headset_only_title" android:title="@string/headset_only_title"
android:defaultValue="false" android:defaultValue="false"
android:summary="@string/headset_only_summary" /> android:summary="@string/headset_only_summary" />
<CheckBoxPreference
android:key="headset_pause"
android:title="@string/headset_pause_title"
android:defaultValue="true"
android:summary="@string/headset_pause_summary" />
<CheckBoxPreference <CheckBoxPreference
android:key="remote_player" android:key="remote_player"
android:title="@string/remote_player_title" android:title="@string/remote_player_title"

View File

@ -279,6 +279,7 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
mHandler.sendMessage(mHandler.obtainMessage(PREF_CHANGED, key)); mHandler.sendMessage(mHandler.obtainMessage(PREF_CHANGED, key));
} }
private boolean mHeadsetPause;
private boolean mHeadsetOnly; private boolean mHeadsetOnly;
private boolean mUseRemotePlayer; private boolean mUseRemotePlayer;
private boolean mNotifyWhilePaused; private boolean mNotifyWhilePaused;
@ -297,7 +298,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
private ArrayList<Song> mSongTimeline; private ArrayList<Song> mSongTimeline;
private int mCurrentSong = -1; private int mCurrentSong = -1;
private int mQueuePos = 0; private int mQueuePos = 0;
private boolean mPlugged = true;
private int mState = STATE_NORMAL; private int mState = STATE_NORMAL;
private boolean mPlayingBeforeCall; private boolean mPlayingBeforeCall;
@ -339,13 +339,10 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
setPlaying(!mMediaPlayer.isPlaying()); setPlaying(!mMediaPlayer.isPlaying());
break; break;
case HEADSET_PLUGGED: case HEADSET_PLUGGED:
boolean plugged = message.arg1 == 1; if (mHeadsetPause) {
if (plugged != mPlugged) { boolean plugged = message.arg1 == 1;
mPlugged = plugged;
if (mCurrentSong == -1)
return;
if (!plugged && mMediaPlayer.isPlaying()) if (!plugged && mMediaPlayer.isPlaying())
setPlaying(false); pause();
} }
break; break;
case PREF_CHANGED: case PREF_CHANGED:
@ -452,6 +449,7 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
mSettings = PreferenceManager.getDefaultSharedPreferences(this); mSettings = PreferenceManager.getDefaultSharedPreferences(this);
mSettings.registerOnSharedPreferenceChangeListener(this); mSettings.registerOnSharedPreferenceChangeListener(this);
mHeadsetPause = mSettings.getBoolean("headset_pause", true);
mHeadsetOnly = mSettings.getBoolean("headset_only", false); mHeadsetOnly = mSettings.getBoolean("headset_only", false);
mUseRemotePlayer = mSettings.getBoolean("remote_player", true); mUseRemotePlayer = mSettings.getBoolean("remote_player", true);
mNotifyWhilePaused = mSettings.getBoolean("notify_while_paused", true); mNotifyWhilePaused = mSettings.getBoolean("notify_while_paused", true);
@ -464,7 +462,9 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
private void loadPreference(String key) private void loadPreference(String key)
{ {
if ("headset_only".equals(key)) { if ("headset_pause".equals(key)) {
mHeadsetPause = mSettings.getBoolean("headset_pause", true);
} else if ("headset_only".equals(key)) {
mHeadsetOnly = mSettings.getBoolean(key, false); mHeadsetOnly = mSettings.getBoolean(key, false);
if (mHeadsetOnly && isSpeakerOn() && mMediaPlayer.isPlaying()) if (mHeadsetOnly && isSpeakerOn() && mMediaPlayer.isPlaying())
pause(); pause();