Add back headset only feature
This commit is contained in:
parent
4191ba031f
commit
4311632dd5
@ -92,5 +92,7 @@ THE SOFTWARE.
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<!-- This is needed for isWiredHeadsetOn() to work in some cases. (bug?) -->
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<supports-screens android:smallScreens="true" />
|
||||
</manifest>
|
||||
|
@ -109,8 +109,10 @@ THE SOFTWARE.
|
||||
<string name="volume_summary">Music volume</string>
|
||||
<string name="media_button_title">Use Headset Controls</string>
|
||||
<string name="media_button_summary">Single click for play/pause. Double click for next.</string>
|
||||
<string name="headset_pause_title">Pause When Headset Disconnected</string>
|
||||
<string name="headset_pause_summary">Pause when the headphones or Bluetooth device are disconnected.</string>
|
||||
<string name="headset_only_title">External Output Only</string>
|
||||
<string name="headset_only_summary">Only play music through an external output (e.g. headphones, Bluetooth)</string>
|
||||
<string name="headset_pause_title">Pause When Unplugged</string>
|
||||
<string name="headset_pause_summary">Pause when the headphones are unplugged.</string>
|
||||
|
||||
<string name="pref_notifications">Notifications</string>
|
||||
<string name="notification_mode_title">Notification Mode</string>
|
||||
|
@ -33,6 +33,11 @@ THE SOFTWARE.
|
||||
android:title="@string/media_button_title"
|
||||
android:summary="@string/media_button_summary"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:key="headset_only"
|
||||
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"
|
||||
|
@ -114,6 +114,10 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
boolean mHeadsetPause;
|
||||
private boolean mScrobble;
|
||||
private int mNotificationMode;
|
||||
/**
|
||||
* If true, audio will not be played through the speaker.
|
||||
*/
|
||||
private boolean mHeadsetOnly;
|
||||
/**
|
||||
* The time to wait before considering the player idle.
|
||||
*/
|
||||
@ -126,6 +130,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private SharedPreferences mSettings;
|
||||
private NotificationManager mNotificationManager;
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
SongTimeline mTimeline;
|
||||
int mState;
|
||||
@ -163,6 +168,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
mMediaPlayer.setOnErrorListener(this);
|
||||
|
||||
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
|
||||
|
||||
SharedPreferences settings = getSettings();
|
||||
settings.registerOnSharedPreferenceChangeListener(this);
|
||||
@ -175,6 +181,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
}
|
||||
mIdleTimeout = settings.getBoolean("use_idle_timeout", false) ? settings.getInt("idle_timeout", 3600) : 0;
|
||||
Song.mDisableCoverArt = settings.getBoolean("disable_cover_art", false);
|
||||
mHeadsetOnly = settings.getBoolean("headset_only", false);
|
||||
|
||||
PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VanillaMusicLock");
|
||||
@ -321,6 +328,10 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
PlaybackActivity.mUpAction = Integer.parseInt(settings.getString(key, "0"));
|
||||
} else if ("swipe_down_action".equals(key)) {
|
||||
PlaybackActivity.mDownAction = Integer.parseInt(settings.getString(key, "0"));
|
||||
} else if ("headset_only".equals(key)) {
|
||||
mHeadsetOnly = settings.getBoolean(key, false);
|
||||
if (mHeadsetOnly && isSpeakerOn())
|
||||
unsetFlag(FLAG_PLAYING);
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,6 +357,14 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if audio would play through the speaker.
|
||||
*/
|
||||
private boolean isSpeakerOn()
|
||||
{
|
||||
return !mAudioManager.isWiredHeadsetOn() && !mAudioManager.isBluetoothA2dpOn() && !mAudioManager.isBluetoothScoOn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the service state.
|
||||
*
|
||||
@ -354,7 +373,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
*/
|
||||
private int updateState(int state)
|
||||
{
|
||||
if ((state & FLAG_NO_MEDIA) != 0 || (state & FLAG_ERROR) != 0)
|
||||
if ((state & FLAG_NO_MEDIA) != 0 || (state & FLAG_ERROR) != 0 || (mHeadsetOnly && isSpeakerOn()))
|
||||
state &= ~FLAG_PLAYING;
|
||||
|
||||
int oldState = mState;
|
||||
|
Loading…
x
Reference in New Issue
Block a user