maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   Stopping music/media player when headset unplugged (https://talk.maemo.org/showthread.php?t=33215)

andyph666 2010-01-12 14:03

Re: Stopping music/media player when headset unplugged
 
I take it this package doesn't work for fremantle? Been looking for something like this.

thp 2010-01-13 16:19

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by andyph666 (Post 466328)
I take it this package doesn't work for fremantle? Been looking for something like this.

Joost Kop sent me a patch that makes it work under Fremantle. I'm just struggling with converting the sysvinit script to a upstart script. It works for the N900 built-in media player and Panucci. MPlayer should also work, but is untested.

thp 2010-01-14 00:03

Re: Stopping music/media player when headset unplugged
 
Ok, I got a first working version packaged up. The autobuilder liked the source, so headphoned should be in Extras-Devel "real soon now", and I'll promote it to Extras-Testing so you can give it some QA love to get it into Extras :)

twaelti 2010-01-14 10:30

Re: Stopping music/media player when headset unplugged
 
Perfect timing :-) I just got fed up enough with the current way that I started to google for "maemo unplug pause" - and here I am, ready to go. Thanks Thomas!

PS: It hasn't yet showed up in extras-devel, autobuilder never pushed it. Guess the repository distribution mechanism is 2nd in line while Nokia distributes the new firmware...

gunni 2010-01-14 11:57

Re: Stopping music/media player when headset unplugged
 
Does this script restart a paused player, too? This would be useful for me, too.

thp 2010-01-14 14:17

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by gunni (Post 470471)
Does this script restart a paused player, too? This would be useful for me, too.

No, right now it just pauses the player whenever the headphone is unplugged. There are some caveats to having it resume playback on reconnect (especially where more applications are concerned).

One example: Assume you have Media Player and Panucci open. It's okay to send a "pause" signal to both. You probably don't want to send a "resume" signal to both, however. Which one to choose then? It's not really obvious. The code is open, so if you want to give it a shot, feel free to do so :)

andyph666 2010-01-14 19:21

Re: Stopping music/media player when headset unplugged
 
thp: any chance we could just download the .deb form of it?

Not a programmer or anything but just trying to help. Couldn't you just resume the last opened program? Thanks for making this app btw.

thp 2010-01-14 20:37

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by andyph666 (Post 471842)
thp: any chance we could just download the .deb form of it?

Here you go: headphoned_1.5_armel.deb

(Usual disclaimer applies. No warranty whatsoever on this binary package. If you don't trust me, please rebuild from source after you have read the code. Downloading random .debs from Teh Internets can really hurt your device.)

Egres 2010-01-14 21:50

Re: Stopping music/media player when headset unplugged
 
This is a great program and thank you for your job, but I have a one wish for it: Can you track 'headphones disconnect' if I talk by phone? I mean the next scenario:

1) I listen some music by headphones
2) I receive a phone call -> the player is paused automatically.
3) I pull off the headphones and answer the call
4) If I just hang off now, the player will automatically continue playing whenever phones is plugged or no. Can you change this behavior for "permanent pause" in this case or this is technically hard to do?

P.S. Sorry, my English is terrible ;-)

Abemelek 2010-01-16 03:27

Re: Stopping music/media player when headset unplugged
 
it works perfectly. :)

bald.eagle.one 2010-01-16 14:08

Re: Stopping music/media player when headset unplugged
 
just found it in extras

thanks!

btw. this should be included in firmware release with an option in settings to switch off if needed to

springah 2010-01-16 14:19

Re: Stopping music/media player when headset unplugged
 
exactly what ive needed - thanks!

gunni 2010-01-16 17:26

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by thp (Post 470881)
No, right now it just pauses the player whenever the headphone is unplugged. There are some caveats to having it resume playback on reconnect (especially where more applications are concerned).

One example: Assume you have Media Player and Panucci open. It's okay to send a "pause" signal to both. You probably don't want to send a "resume" signal to both, however. Which one to choose then? It's not really obvious. The code is open, so if you want to give it a shot, feel free to do so :)

Thx. Ok, i can get that this is not as easy as i thought. When i get an idea i will ask again :)

josetaza 2010-01-19 06:25

Re: Stopping music/media player when headset unplugged
 
About the resume play when the headphone is re-connected:
I started on developing an application where this should be possible. As user of this application you are able to select what should be done (play/pause) when the headphone is connected or disconnected.
Eventualy I want it to be capable of doing more than react on connected headphones. See also:
https://garage.maemo.org/projects/actionmanager/

Currently it does pause the mediaplayer when disconnecting the headphone and start playing again when connected, but this is fixed. No UserInterface is made yet for changing settings.

Unfortunatly I havent been able to upload this to the repository yet. So be patient...

unkno 2010-01-19 08:35

Re: Stopping music/media player when headset unplugged
 
I have a question...if headphoned is kept running in the background, won't it eat up CPU cycles? If it does eat a noticeable amount, is it possible to code it in such a way that it will only run when it detects the headphone is connected and also end the task after pausing when headphones are removed.

Edit: I also agree that this should be included in the next firmware (as a setting)...maybe someone should make a bugzilla report asking for an enhancement.

thp 2010-01-19 12:04

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by unkno (Post 481477)
I have a question...if headphoned is kept running in the background, won't it eat up CPU cycles? If it does eat a noticeable amount, is it possible to code it in such a way that it will only run when it detects the headphone is connected and also end the task after pausing when headphones are removed.

That's actually how it works: headphoned installs a I/O watch that gets executed every time the state file changes (which is only when the headphones get plugged/unplugged). After that, it notifies all known media players and then returns to the main loop which again is waiting for I/O (by blocking on the state file). If you use "ps", you should see that headphoned is sleeping ("S") most of the time.

The only thing that headphoned uses constantly is a bit of your main memory.

See http://git.maemo.org/git/headphoned/...c/headphoned.c

OVK 2010-01-19 12:11

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by thp (Post 481742)
That's actually how it works: headphoned installs a I/O watch that gets executed every time the state file changes (which is only when the headphones get plugged/unplugged). After that, it notifies all known media players and then returns to the main loop which again is waiting for I/O (by blocking on the state file). If you use "ps", you should see that headphoned is sleeping ("S") most of the time.

The only thing that headphoned uses constantly is a bit of your main memory.

See http://git.maemo.org/git/headphoned/...c/headphoned.c

Would it be possible to expand the functions of headphoned app so that it could also give other commands than just pause to Mediaplayer?

The case that I have in mind is the wired remotes that Nokia has available. Those have for example volume buttons and play/pause/forward etc.

This subject is also discussed here: http://talk.maemo.org/showthread.php?t=21182 (see the pages 3 and 4). I already mentioned your app there.

Alan_Peery 2010-01-20 14:01

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by adolfotregosa (Post 428234)
How about pausing the player when a2dp is disconnected ??

N97 had this detail while the n900 does not, and on the car it really makes a diference..

Quote:

Originally Posted by thp (Post 428597)
You can check out the code from https://garage.maemo.org/projects/headphoned and add the code :)

If you send me some a2dp hardware, I can try to implement it :p

Send me a PM with details, I'll send you a BH-103 as a thank you for the work you've done already.

If you find a way to have separate volume levels for speaker, headphones, and A2DP, you'll make me happy on my train commutes. :-)

VRe 2010-01-20 20:07

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by thp (Post 470881)
No, right now it just pauses the player whenever the headphone is unplugged. There are some caveats to having it resume playback on reconnect (especially where more applications are concerned).

One example: Assume you have Media Player and Panucci open. It's okay to send a "pause" signal to both. You probably don't want to send a "resume" signal to both, however. Which one to choose then? It's not really obvious. The code is open, so if you want to give it a shot, feel free to do so :)

Installed headphoned and pausing works perfectly!

For replay I started thinking.. if the supported players are more or less known, it is possible to check which ones are running. If there is only one program running, there is no problem in choosing. If there is more than one program running, a dialog could be show listing the programs i.e. "Headphones reconnected, continue playing with [panucci] [media player] [none]?"

DaSilva 2010-01-21 09:18

Re: Stopping music/media player when headset unplugged
 
I think only one player is actively playing something at the same time so is it possible to detect it and then resume it when the headphones are being reconnected?

slender 2010-01-21 09:21

Re: Stopping music/media player when headset unplugged
 
Could soneone test this.
- phone rangs
-- disconnect headphones and answer
- end call
- music plays from speakers?

Maybe this just user error but happened me once.

mike2k4 2010-01-22 00:03

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by slender (Post 486113)
Could soneone test this.
- phone rangs
-- disconnect headphones and answer
- end call
- music plays from speakers?

Maybe this just user error but happened me once.

This has happened to me since the first firmware update, while at work too :mad: I didnt even have this app at all either.

mike2k4 2010-01-22 19:02

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by thp (Post 428597)
You can check out the code from https://garage.maemo.org/projects/headphoned and add the code :)

If you send me some a2dp hardware, I can try to implement it :p

I can't seem to figure out how to determine when a bluetooth headset is disconnected. It seems to work different from the way headphones are unplugged since they use a "state" file. When I disconnect my car stereo's bluetooth, the following line shows up in dbus-monitor:

Code:

signal sender=:1.3 -> dest=(null destination) serial=220 path=/org/maemo/Playback/Manager; interface=org.maemo.Playback.Manager; member=BluetoothOverride
int32 -1

I do not know if this will help. If not, is there a way to see if the bluetooth headset is currently enabled in the status-menu?

andrei1089 2010-01-27 17:05

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by slender (Post 486113)
Could soneone test this.
- phone rangs
-- disconnect headphones and answer
- end call
- music plays from speakers?

Maybe this just user error but happened me once.

exactly the same happened to me today

Alan_Peery 2010-01-27 19:10

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by mike2k4 (Post 489212)

I do not know if this will help. If not, is there a way to see if the bluetooth headset is currently enabled in the status-menu?

I am guessing by analogy here: is there something like /proc/usb called /proc/bluetooth that you could inspect once you've seen one of those events?

qwerty12 2010-01-27 20:12

Re: Stopping music/media player when headset unplugged
 
Yes, you can listen for D-Bus signals saying that the headphones have been removed (mike2k4, sniff the system bus, instead), but there's an easier way: Don't use GIOChannels to monitor the state file, but use libhal to listen for computer_logicaldev_input_1 being removed. This way, you kill two birds with one stone: Removing a wired or a bluetooth headset causes the same event to be broadcast by HAL - "computer_logicaldev_input_1 removed".

ziller 2010-01-27 20:23

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by slender (Post 486113)
Could soneone test this.
- phone rangs
-- disconnect headphones and answer
- end call
- music plays from speakers?

Maybe this just user error but happened me once.

Happened a couple of times here too, but I've so far not been able to replicate it under "controlled" conditions. But I seem to be having the same behaviour with disconnected skype calls only. Though still not every time.

headphoned would really need a bugtracker....

thp 2010-01-27 20:50

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by ziller (Post 498148)
Happened a couple of times here too, but I've so far not been able to replicate it under "controlled" conditions. But I seem to be having the same behaviour with disconnected skype calls only. Though still not every time.

I've experienced this too at times. Feels like some audio (ring)buffer being played once more - probably an issue with some ,,lower layer`` (PA, GStreamer, ALSA?).

Quote:

Originally Posted by ziller (Post 498148)
headphoned would really need a bugtracker....

https://garage.maemo.org/tracker/?group_id=1092

qwerty12 2010-01-28 17:22

Re: Stopping music/media player when headset unplugged
 
1 Attachment(s)
Quote:

Originally Posted by qwerty12 (Post 498124)
Yes, you can listen for D-Bus signals saying that the headphones have been removed (mike2k4, sniff the system bus, instead), but there's an easier way: Don't use GIOChannels to monitor the state file, but use libhal to listen for computer_logicaldev_input_1 being removed. This way, you kill two birds with one stone: Removing a wired or a bluetooth headset causes the same event to be broadcast by HAL - "computer_logicaldev_input_1 removed".

OK, decided to give this a go and came up with http://slexy.org/view/s2HFCPBXm5 - this is unofficial, of course.

I'm incompetent, tired, and working with a 15" monitor so I ended up removing the parts of the code that make no sense under Fremantle just so that I could read the code without giving myself a headache (not in the sense that thp's code is awful but, rather, in the sense that I couldn't be arsed to keep scrolling up). Not to mention that I much prefer using the GLib bindings to D-Bus (I was sorely tempted to do so until I saw thp was already using libdbus and that I could get a DBusConnection from the osso_context_t)...

This works for me using the wired headset that came with my N810 and with an el-cheapo, £11 iTech Bluetooth headset I got from eBay. A compiled binary is attached. I'd be curious to know if it works for anyone else. "It" being having the Media Player paused when a Bluetooth headset is disconnected.

unkno 2010-01-30 05:19

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by slender (Post 486113)
Could soneone test this.
- phone rangs
-- disconnect headphones and answer
- end call
- music plays from speakers?

Maybe this just user error but happened me once.

This has to do with the way Maemo works. Normally, when a call comes in, the media player is paused and will automatically resume when the call is ended. Since the phone rings with the headphone plugged, unplugging the headphones will pause the already paused music; but when the call is over, maemo will signal the media player to resume playing. I don't think it's possible to fix this given the way it is designed.

Edit: one more vote and it'll be in extras

opax 2010-01-31 21:16

Re: Stopping music/media player when headset unplugged
 
hello all

What's the command to pause the mediaplayer not the Gstreamer renderer?it is linked to the playback library
I think this is the solution to this

Quote:

Could soneone test this.
- phone rangs
-- disconnect headphones and answer
- end call
- music plays from speakers?

Maybe this just user error but happened me once.

Kevven 2010-02-02 00:22

Re: Stopping music/media player when headset unplugged
 
Does the headphone daemon affect power or memory use? Just installed it, and it works great :)

andrei1089 2010-02-02 00:31

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by Kevven (Post 506035)
Does the headphone daemon affect power or memory use? Just installed it, and it works great :)

Headphone daemon is sleeping almost all the time ( wakes up only when you unplug the headphone) so it shouldn't affect the battery life.

Kevven 2010-02-02 00:39

Re: Stopping music/media player when headset unplugged
 
Thank you for the quick reply! =)

neboja 2010-02-02 10:53

Re: Stopping music/media player when headset unplugged
 
i was wondering..... is it posible to have a "switch" to enable/disable a Headphone deamon???? it would be good thing.... for example... say you are in some form of activitty, and your phone slips somevhere... you can't find him... it would be a god thing if you can hear him where is it...
or you are in a public transportation... someone slips a hand into your pocket... and a way he go!!! :P
i say... when you are in some siituations when is good thing to hear your phone when the earphones are not jacked, the deamon is disabled... but also there is a situations that is good to just unplug earphones to pouse a MP...
what do you think about that??? O_o

thp 2010-02-02 13:35

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by neboja (Post 506563)
i was wondering..... is it posible to have a "switch" to enable/disable a Headphone deamon???? it would be good thing.... for example... say you are in some form of activitty, and your phone slips somevhere... you can't find him... it would be a god thing if you can hear him where is it...
or you are in a public transportation... someone slips a hand into your pocket... and a way he go!!! :P

The initial reason for creating headphoned in the first place is for "public transportation situations", so if you are afraid of someone stealing your device in public transportation, simply don't install headphoned ;)

The same goes for losing your phone - simply let someone else call you, that's what you would do when you lose a "normal" phone, too. I personally simply SSH into my phone if I don't know where it is in my apartment and use:

Code:

panucci /path/to/some/mp3file.mp3
After that, simply follow the noise.

Quote:

Originally Posted by neboja (Post 506563)
i say... when you are in some siituations when is good thing to hear your phone when the earphones are not jacked

To disable:

Code:

killall headphoned
To enable:

Code:

/usr/sbin/headphoned &
It also only stops the media player - everything else is not touched (e.g. ring tones, alarms, reminders, ...).

mike2k4 2010-02-02 14:04

Re: Stopping music/media player when headset unplugged
 
Quote:

Originally Posted by qwerty12 (Post 499729)
OK, decided to give this a go and came up with http://slexy.org/view/s2HFCPBXm5 - this is unofficial, of course.

I'm incompetent, tired, and working with a 15" monitor so I ended up removing the parts of the code that make no sense under Fremantle just so that I could read the code without giving myself a headache (not in the sense that thp's code is awful but, rather, in the sense that I couldn't be arsed to keep scrolling up). Not to mention that I much prefer using the GLib bindings to D-Bus (I was sorely tempted to do so until I saw thp was already using libdbus and that I could get a DBusConnection from the osso_context_t)...

This works for me using the wired headset that came with my N810 and with an el-cheapo, £11 iTech Bluetooth headset I got from eBay. A compiled binary is attached. I'd be curious to know if it works for anyone else. "It" being having the Media Player paused when a Bluetooth headset is disconnected.

Thank you!!! I will give it a shot to see if it works with my car stereo. I was unaware of libhal.

neboja 2010-02-02 14:05

Re: Stopping music/media player when headset unplugged
 
ok... so these are just scripts that i put in xterm.... and that's it??? wright?
thnks!
anyway.... all i want is to controll thigs on my phone... i am not a programer, and not an advanced user,... so it would allways be halpfull to developers make there apps more controlable...
i know i ask to much... but hey! :D

thp 2010-02-02 20:04

Re: Stopping music/media player when headset unplugged
 
I've received my Bluetooth headset today (thanks to Alan Peery!), and thanks to the work done by Faheem, it was easy to integrate support for Bluetooth headset disconnects to headphoned and also test it thoroughly. It also seems that for headphones *without* microphone, Hal does not detect a device disconnect, so I had to leave the state file-based code in there. I did some clean-ups, re-added support for Diablo, but removed the volume control code (which didn't really work on Diablo and is unnecessary on Fremantle).

In short: headphoned 1.6 with Bluetooth support is currently going through the autobuilder, and should be landing in Extras-Devel soon. Again, credits for this release go to Alan and Faheem - thanks guys!

(A side effect is that disconnecting a wired headset with microphone now causes two signals - one from the state file and one from Hal - to be emitted, but for Media Player and Panucci, this does not matter, as they don't unpause when the second "pause" signal is sent.)

DaSilva 2010-02-05 09:48

Re: Stopping music/media player when headset unplugged
 
I had a strange issue a few days ago but I don't know if it is related to headphoned: I unplugged my headset while playing music, the music stopped as expected. After a few days and a few restarts I plugged in my headset again and it began to play from the last active source in the default media player which was not what I wanted (maybe this behaviour could be useful for a short time after unplugging but not after a few days + restarts).
Can it be related to headphoned?


All times are GMT. The time now is 02:45.

vBulletin® Version 3.8.8