FS#12097 - Android: headphone detection (enabling pause on unplug)

Attached to Project: Rockbox
Opened by Dominik Riebeling (bluebrother) - Wednesday, 04 May 2011, 16:57 GMT
Last edited by Dominik Riebeling (bluebrother) - Saturday, 04 June 2011, 19:17 GMT
Task Type Patches
Category Music playback
Status Closed
Assigned To No-one
Operating System Android
Severity Low
Priority Normal
Reported Version Daily build (which?)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


This patch adds support for headphone detection on Android, thus enabling pause on headphone (un)plug.

There are two issues with this (though not caused by this patch):
- 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.
This task depends upon

Closed by  Dominik Riebeling (bluebrother)
Saturday, 04 June 2011, 19:17 GMT
Reason for closing:  Accepted
Comment by Dominik Riebeling (bluebrother) - Wednesday, 04 May 2011, 17:00 GMT
Oops, had a change in the debouncing timeout in the previous patch. While the debouncing timeout might be a bit big it's definitely nothing this patch should change. Updated patch.
Comment by Paul Louden (darkkone) - Wednesday, 04 May 2011, 21:07 GMT
With Audible's pause-on-unplug option, I never hear audio from the speakers. If we removed the debouncing, is that would happen here? I assume the delay in reporting the unplug is the same as the delay in switching audio playback from headphones to speaker, since I've never heard it play out the speakers after an unplug and before a pause in Audible.
Comment by Hayden Pearce (St.) - Thursday, 05 May 2011, 08:50 GMT
Could we mute playback when unplug is detected so that even if it is routed to the internal speaker for <N> period, there won't be the nasty blast of noise?
Comment by Hayden Pearce (St.) - Thursday, 05 May 2011, 08:56 GMT
OOOps, scratch that. I read it wrong, I though the delay was between unplug being detected and pause applied. Not between the cable being unplugged and the unplug being detected.
Comment by Antoine Cellerier (dionoea) - Tuesday, 10 May 2011, 13:17 GMT
If I remember correctly from my preliminary research into the topic a few weeks ago, it is recommended to also listen to to prevent the event delay on headphone unplugging.
Comment by Dominik Riebeling (bluebrother) - Thursday, 12 May 2011, 20:29 GMT
That's a good hint. I've implemented it (not sure if it's done in a good way but it works for me) and (after also decreasing the Rockbox internal debouncing from 1s to 0.5s) I don't get audio played back through the speaker anymore on unplug. I don't know if other phones have different delays for that and might still show the issue with the current delay. Apply on top of the previous patch.