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_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_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>

View File

@ -7,6 +7,11 @@
android:title="@string/headset_only_title"
android:defaultValue="false"
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
android:key="remote_player"
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));
}
private boolean mHeadsetPause;
private boolean mHeadsetOnly;
private boolean mUseRemotePlayer;
private boolean mNotifyWhilePaused;
@ -297,7 +298,6 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
private ArrayList<Song> mSongTimeline;
private int mCurrentSong = -1;
private int mQueuePos = 0;
private boolean mPlugged = true;
private int mState = STATE_NORMAL;
private boolean mPlayingBeforeCall;
@ -339,13 +339,10 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
setPlaying(!mMediaPlayer.isPlaying());
break;
case HEADSET_PLUGGED:
boolean plugged = message.arg1 == 1;
if (plugged != mPlugged) {
mPlugged = plugged;
if (mCurrentSong == -1)
return;
if (mHeadsetPause) {
boolean plugged = message.arg1 == 1;
if (!plugged && mMediaPlayer.isPlaying())
setPlaying(false);
pause();
}
break;
case PREF_CHANGED:
@ -452,6 +449,7 @@ public class PlaybackService extends Service implements Runnable, MediaPlayer.On
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
mSettings.registerOnSharedPreferenceChangeListener(this);
mHeadsetPause = mSettings.getBoolean("headset_pause", true);
mHeadsetOnly = mSettings.getBoolean("headset_only", false);
mUseRemotePlayer = mSettings.getBoolean("remote_player", 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)
{
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);
if (mHeadsetOnly && isSpeakerOn() && mMediaPlayer.isPlaying())
pause();