From 6c22be4a3db4ad72acf67f99059872e92d1931b4 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sat, 4 Jun 2011 19:17:47 +0000 Subject: Android: implement headphone detection thus enabling pause on unplug (FS#12097). Listen to headphone plug events. There are currently two glitches with this: - Android takes a while until it reports the unplug event, so there will be some delay until playback gets paused. This is an Android limitation. - Rockbox debounces headphone state changes for one second. Therefore playback will shortly be routed to the speaker on unplug until Rockbox does the actual pause. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29956 a1c6a512-1295-4272-9138-f99709370657 --- android/src/org/rockbox/RockboxService.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'android/src') diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java index 346e4a1..71b133e 100644 --- a/android/src/org/rockbox/RockboxService.java +++ b/android/src/org/rockbox/RockboxService.java @@ -64,10 +64,13 @@ public class RockboxService extends Service private static volatile boolean rockbox_running; private Activity current_activity = null; private IntentFilter itf; + private IntentFilter ifh; private BroadcastReceiver batt_monitor; + private BroadcastReceiver headphone_monitor; private RunForegroundManager fg_runner; private MediaButtonReceiver mMediaButtonReceiver; private int battery_level; + private int headphone_state; private ResultReceiver resultReceiver; public static final int RESULT_INVOKING_MAIN = 0; @@ -339,6 +342,24 @@ public class RockboxService extends Service registerReceiver(batt_monitor, itf); } + + private void initHeadphoneMonitor() + { + ifh = new IntentFilter(Intent.ACTION_HEADSET_PLUG); + headphone_monitor = new BroadcastReceiver() + { + @Override + public void onReceive(Context context, Intent intent) + { + int state = intent.getIntExtra("state", -1); + LOG("headphone state:" + state); + headphone_state = state; + } + }; + registerReceiver(headphone_monitor, ifh); + } + + void startForeground() { fg_runner.startForeground(); -- cgit v1.1