Simplified code
This commit is contained in:
parent
3cee523a08
commit
55be2344ce
|
@ -1092,21 +1092,10 @@ public class PlaybackService extends Service {
|
||||||
if (state != -1) {
|
if (state != -1) {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Headset plug event. State is " + state);
|
Log.d(TAG, "Headset plug event. State is " + state);
|
||||||
boolean pauseOnDisconnect = PreferenceManager
|
if (state == UNPLUGGED && status == PlayerStatus.PLAYING) {
|
||||||
.getDefaultSharedPreferences(
|
|
||||||
getApplicationContext())
|
|
||||||
.getBoolean(
|
|
||||||
PodcastApp.PREF_PAUSE_ON_HEADSET_DISCONNECT,
|
|
||||||
false);
|
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "pauseOnDisconnect preference is "
|
Log.d(TAG, "Headset was unplugged during playback.");
|
||||||
+ pauseOnDisconnect);
|
pauseIfPauseOnDisconnect();
|
||||||
if (state == UNPLUGGED && pauseOnDisconnect
|
|
||||||
&& status == PlayerStatus.PLAYING) {
|
|
||||||
if (AppConfig.DEBUG)
|
|
||||||
Log.d(TAG,
|
|
||||||
"Pausing playback because headset was disconnected");
|
|
||||||
pause(false, true);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Received invalid ACTION_HEADSET_PLUG intent");
|
Log.e(TAG, "Received invalid ACTION_HEADSET_PLUG intent");
|
||||||
|
@ -1120,22 +1109,23 @@ public class PlaybackService extends Service {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
// sound is about to change, eg. bluetooth -> speaker
|
// sound is about to change, eg. bluetooth -> speaker
|
||||||
boolean pauseOnDisconnect = PreferenceManager
|
|
||||||
.getDefaultSharedPreferences(
|
|
||||||
context.getApplicationContext())
|
|
||||||
.getBoolean(
|
|
||||||
PodcastApp.PREF_PAUSE_ON_HEADSET_DISCONNECT,
|
|
||||||
false);
|
|
||||||
if(pauseOnDisconnect&&status==PlayerStatus.PLAYING) {
|
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG,
|
Log.d(TAG, "Pausing playback because audio is becoming noisy");
|
||||||
"Pausing playback because audio is becoming noisy");
|
pauseIfPauseOnDisconnect();
|
||||||
pause(false, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// android.media.AUDIO_BECOMING_NOISY
|
// android.media.AUDIO_BECOMING_NOISY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Pauses playback if PREF_PAUSE_ON_HEADSET_DISCONNECT was set to true. */
|
||||||
|
private void pauseIfPauseOnDisconnect() {
|
||||||
|
boolean pauseOnDisconnect = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(getApplicationContext())
|
||||||
|
.getBoolean(PodcastApp.PREF_PAUSE_ON_HEADSET_DISCONNECT, false);
|
||||||
|
if (pauseOnDisconnect && status == PlayerStatus.PLAYING) {
|
||||||
|
pause(false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue