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)

Tintin 2009-10-21 07:42

Stopping music/media player when headset unplugged
 
One thing that i really like about my Zune is that whenever I pull the headset out (which I tend to do a lot by accident) - the player stops. Obviously that makes sense on the Zune (non-HD) as it doesnt have any external speakers.

I would love for there to be an option to have my N810 act in the same way;
If playing a movie/music/podcast and the headset is pulled out...then stop the player. If you want to continue to play through your speakers just press play and it continues playing.

Happened again today that I stand in line and the headset pulls out and suddenly I'm blasting Cypress Hill from my right pocket....

Thing is...would such an option have to be implemented into each possible media player...or could it somehow be a global, application-independent option...somehow?

vkv.raju 2009-10-21 08:21

Re: Stopping music/media player when headset unplugged
 
I like this. This will be a nice feature. Will save many from those little occasional embarrassments.
Pause audio/video when the headset is pulled out.

thp 2009-10-21 08:33

Re: Stopping music/media player when headset unplugged
 
You can detect headphone plug/unplug events via D-Bus, so you could write a service that then notifies the media players.

BTW: On the N900, you can non-headphone and headphone volume independently, so if you set the volume to zero when the headphones are not plugged in, then connect the headphones and set some positive volume, if you accidentally unplug the headphones in a subway or bus, people won't be distracted by whatever fancy music you decided to listen to today.

That said, a mini-daemon that listens on D-Bus for headphone unplug changes and sets/remembers/restores the volume for each different mode would probably be easy to do and avoid what I call the "public transport situation" ("waiting in line situation" for you ;) for all media players.

thp 2009-10-21 08:39

Re: Stopping music/media player when headset unplugged
 
Oh, and I just found out (while searching for code) that there have already been several threads about this:

http://talk.maemo.org/showthread.php?t=26925

http://talk.maemo.org/showthread.php?t=24975

..and the solution (as a package) is here:
http://talk.maemo.org/showthread.php?t=21182

..or if you prefer powerlaunch:
http://talk.maemo.org/showpost.php?p...7&postcount=18

zerojay 2009-10-21 10:32

Re: Stopping music/media player when headset unplugged
 
Only problem with this is that sometimes the N900 seems to forget that there are headphones plugged in from time to time and the headphones icon disappears from the status bar.

thp 2009-10-21 12:22

Re: Stopping music/media player when headset unplugged
 
1 Attachment(s)
Here's a quicky hacked together version of what you want. Compiled against Diablo's SDK. Source + Git repository included.

Either compile it yourself in the SDK or trust my binary and copy headphoned-armel-diablo to your N8x0 and then start it. Everytime the headphone is disconnected, headphoned will send a "pause" event (the same as clicking on pause in the Media Player) to the player.

Tintin 2009-10-21 13:45

Re: Stopping music/media player when headset unplugged
 
Hi and wow thanks for the super quick 'fix' :)

I'm still new to the Linux world so sorry for the follow-up questiom: I downloaded your zipfile to my N810 and unzipped it. I can see the files/directories it created (including the headphoned-armel-diablo file in the main /headphoned folder - but how do I actually open/install it? I tried browsing to it through the application manager but wasn't able to find anything I could install.

Man, if this will work this will be awesome :)

Edit: I tried apt-get -f install headphoned-armel-diablo in the /headphoned folder (while I was root) but got the error 'Couldnt find package headphoned-armel-diablo'

Also tried dpkg -i headphoned-armel-diablo but with no luck

thp 2009-10-21 16:43

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

Originally Posted by Tintin (Post 353895)
Hi and wow thanks for the super quick 'fix' :)

I'm still new to the Linux world so sorry for the follow-up questiom: I downloaded your zipfile to my N810 and unzipped it. I can see the files/directories it created (including the headphoned-armel-diablo file in the main /headphoned folder - but how do I actually open/install it? I tried browsing to it through the application manager but wasn't able to find anything I could install.

Man, if this will work this will be awesome :)

Edit: I tried apt-get -f install headphoned-armel-diablo in the /headphoned folder (while I was root) but got the error 'Couldnt find package headphoned-armel-diablo'

Also tried dpkg -i headphoned-armel-diablo but with no luck

It's just a binary executable, no package (yet..). You can start it like this (run it as normal user, there is no need to run it as root):

Code:

chmod +x headphoned-armel-diablo
./headphoned-armel-diablo &

The first command makes the file executable and you only need to do it once.

The ampersand [&] will cause it to run in the background. You can use "ps ax | grep headphoned" to check if it's running and you can use "killall headphoned-armel-diablo" to kill it.

Here's a nice beginner tutorial for getting used to the command line: http://www.linuxcommand.org/

HTH.

Tintin 2009-10-22 04:24

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

Originally Posted by thp (Post 354183)
It's just a binary executable, no package (yet..). You can start it like this (run it as normal user, there is no need to run it as root):

Code:

chmod +x headphoned-armel-diablo
./headphoned-armel-diablo &

The first command makes the file executable and you only need to do it once.

The ampersand [&] will cause it to run in the background. You can use "ps ax | grep headphoned" to check if it's running and you can use "killall headphoned-armel-diablo" to kill it.

Here's a nice beginner tutorial for getting used to the command line: http://www.linuxcommand.org/

HTH.

Hey and thanks again.
I wasn't sure if the code you included was supposed to be run as two entries or as one long sentence.
I tried both but did not seem to do anything.
When executing the first row I don't get any confirmation or error message.
When executing the second row I got 'no permission'.
I tried checking for active processes using an app i got running in tne status barr but it didnt show there - and i also tried pulling out the cord whilst playing a podcast through gpodder/panucci but the player did not pause.

Sorry for being new to all of this and making helping out a lenghty process.

(Also..how do I get a 'pipe' as in your example for how to check what processes are active using my N810 keyboard?)

Suurorca 2009-10-22 04:51

Re: Stopping music/media player when headset unplugged
 
Sounds like you are perhaps in the wrong directory when you execute the chmod command. Try moving to the directory you extracted with command "cd" [directory]. To make sure the chmod worked, you can run "ls -la", it should show something like "-r-x------" [filename], where "x" means you can now run the application.

Symbol "|" is called pipe, and it gives the output of first command to the second command. Most usual use case is probably finding some specific string in a long text output, like: "ps aux | grep [name of the program]". Not sure what you need to press to get it out of n810 ;)

Oh, and the "ps aux" above lists all the running processes.


Quote:

Originally Posted by Tintin (Post 354921)
Hey and thanks again.
I wasn't sure if the code you included was supposed to be run as two entries or as one long sentence.
I tried both but did not seem to do anything.
When executing the first row I don't get any confirmation or error message.
When executing the second row I got 'no permission'.
I tried checking for active processes using an app i got running in tne status barr but it didnt show there - and i also tried pulling out the cord whilst playing a podcast through gpodder/panucci but the player did not pause.

Sorry for being new to all of this and making helping out a lenghty process.

(Also..how do I get a 'pipe' as in your example for how to check what processes are active using my N810 keyboard?)


thp 2009-10-22 08:58

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

Originally Posted by Tintin (Post 354921)
I wasn't sure if the code you included was supposed to be run as two entries or as one long sentence.
I tried both but did not seem to do anything.
When executing the first row I don't get any confirmation or error message.
When executing the second row I got 'no permission'.
I tried checking for active processes using an app i got running in tne status barr but it didnt show there - and i also tried pulling out the cord whilst playing a podcast through gpodder/panucci but the player did not pause.

You should place the file in /home/user, as (I think) the SD cards are mounted with noexec (meaning you cannot execute applications on it). If you have the binary in the root of /media/mmc2/ (for example), move them (using the "mv" command) to /home/user, then cd into /home/user, make it executable (just to make sure) and start it:

Code:

mv /media/mmc2/headphoned-armel-diablo /home/user/
cd /home/user/
chmod +x headphoned-armel-diablo
./headphoned-armel-diablo &

The pause setting only works for the built-in Media Player right now, not for Panucci (or any other media player). Adding support for this would not be too difficult, however.

thp 2009-10-22 15:14

Re: Stopping music/media player when headset unplugged
 
I have now created a proper package with an init script that takes care of starting headphoned when the system starts (and on installation). The package is called "headphoned" ("Headphone daemon" in the Application Manager) and will be available in Extras-Devel right now. Product page and garage project (for hosting the source) are in the works...

Flandry 2009-10-22 15:18

Re: Stopping music/media player when headset unplugged
 
I had a "public transit situation" the other day and found myself wishing for just this feature. Awesome.

davost 2009-10-22 16:08

Thanks
 
Thanks for this useful app.
Installed it from the rep and it works like a charm.

Tintin 2009-10-23 07:01

Re: Stopping music/media player when headset unplugged
 
Maybe it's me but I don't get this to work.

I downloaded the headphone daemon from the app manager. It says it installed ok.
I start up gpodder and launch a podcast so it starts playing through panucci.
I pull out the headset and the podcast continues to play through the speakers :(

When I look at 'active processes' I see headphoned running (964kb).

Help :(

thp 2009-10-23 10:23

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

Originally Posted by Tintin (Post 356167)
I downloaded the headphone daemon from the app manager. It says it installed ok.
I start up gpodder and launch a podcast so it starts playing through panucci.

Right now, the headphone daemon only sends the pause signal to the built-in media player, not Panucci. It works fine with the media player, just tested it some minutes ago.

Tintin 2009-10-23 20:19

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

Originally Posted by thp (Post 356297)
Right now, the headphone daemon only sends the pause signal to the built-in media player, not Panucci. It works fine with the media player, just tested it some minutes ago.

Ah, that would explain it :)

Any chance that 1.3 will allow panucci and Mplayer to be paused as well? :)

davost 2009-10-25 11:40

Re: Stopping music/media player when headset unplugged
 
Once I made a script to pause Panucci. This was the magic line
Maybe this can help in some way

Code:

dbus-send --type="method_call" --dest=org.panucci.panucciInterface /panucciInterface org.panucci.panucciInterface.playPause

thp 2009-10-25 12:01

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

Originally Posted by Tintin (Post 356835)
Any chance that 1.3 will allow panucci and Mplayer to be paused as well? :)

I have some idea how to implement it for MPlayer, and thanks to the previous post, adding support for Panucci does not seem to be too difficult, either. Free time is lacking atm. Give me some days/weeks. The code is open, and the Git repository available on Garage, in case anyone wants to submit a patch :)

Tintin 2009-11-07 17:02

Re: Stopping music/media player when headset unplugged
 
I had another 'incident' the other day where panucci started blasting the latest edition of Coverville to all the people on the bus :)

silvermountain 2009-11-19 21:00

Re: Stopping music/media player when headset unplugged
 
This would indeed be a very useful application - and seems like a well implemented one (no interface, etc - just auto-pause when headset is unplugged) - if it would support more of the media players.

Thor 2009-11-19 21:13

Re: Stopping music/media player when headset unplugged
 
A setting within headsets or media player would be great !

thp 2009-11-19 22:52

Re: Stopping music/media player when headset unplugged
 
Ok you asked for it.. headphoned 1.3 (currently wandering through the autobuilder) gained support for pausing Panucci in addition to the built-in Media Player. The only other media player that is on my roadmap would be MPlayer, and that will be a bit more tricky :)

thp 2009-11-20 09:21

Re: Stopping music/media player when headset unplugged
 
headphoned 1.3 is now in Extras-Devel for Chinook and Diablo. Please test this release, and report any issues here. I will push the package to Extras if no bugs surface in the next few days. Thankd for your help!

silvermountain 2009-11-21 00:24

Re: Stopping music/media player when headset unplugged
 
I installed 1.3 and, playing with panucci it seems to pause the player perfectly.
If I play through the speakers and insert the headphones it continues to play through the headphones without a pause - which I think works great.

Thanks, this was much needed!

thp 2009-11-21 18:06

Re: Stopping music/media player when headset unplugged
 
headphoned 1.4 is now in Extras-Devel for Chinook and Diablo, and should support MPlayer in addition to Panucci and Media Player. This should also work for applications that use MPlayer as their backend (e.g. Canola).

OVK 2009-11-27 09:28

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

Originally Posted by thp (Post 385391)
headphoned 1.4 is now in Extras-Devel for Chinook and Diablo, and should support MPlayer in addition to Panucci and Media Player. This should also work for applications that use MPlayer as their backend (e.g. Canola).

Any change of getting this functionality for N900? At least I could not find a way to stop the music from playing in N900 speakers when the headphone plug was pulled out.

thp 2009-11-27 10:48

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

Originally Posted by OVK (Post 395439)
Any change of getting this functionality for N900? At least I could not find a way to stop the music from playing in N900 speakers when the headphone plug was pulled out.

The N900 maintains two different volume levels (for plugged and unplugged headphones), so to avoid public transport situations, you just have to unplug your headphones, set the volume to zero, plug them in again, and set your preferred volume. Whenever the headphones get unplugged, the volume will be muted, and when they are reconnected, the volume will be restored.

That said, there might be a use case for having headphoned the N900 as well, just have not got around to do it, as the volume feature described above fixes public transport situations for me already ;)

OVK 2009-11-27 12:08

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

Originally Posted by thp (Post 395566)
The N900 maintains two different volume levels (for plugged and unplugged headphones), so to avoid public transport situations, you just have to unplug your headphones, set the volume to zero, plug them in again, and set your preferred volume. Whenever the headphones get unplugged, the volume will be muted, and when they are reconnected, the volume will be restored.

That said, there might be a use case for having headphoned the N900 as well, just have not got around to do it, as the volume feature described above fixes public transport situations for me already ;)

OK, thanks! That also explains why I almost blew my ears: I set the volume quiet when using speakers, connected the headphones and started to wonder why the music was so terribly loud... ;)

Is it by the way possible to send other commands besides PAUSE with your program? I have understood that it is for example possible to control Nokia 5800 XpressMusic's music player with Nokia AD-54 remote control. I tested the AD-54 with N900 and it does not work. I was just wondering if this is a hardware limitation or software limitation.

Nokia AD-54: http://europe.nokia.com/find-product...ts/hs-45-ad-54

5tapl3r 2009-12-14 17:10

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

Originally Posted by thp (Post 395566)
The N900 maintains two different volume levels (for plugged and unplugged headphones), so to avoid public transport situations, you just have to unplug your headphones, set the volume to zero, plug them in again, and set your preferred volume. Whenever the headphones get unplugged, the volume will be muted, and when they are reconnected, the volume will be restored.

now does this mute your phone so you can't hear it ring, or does that not factor into the equation?

Talvis 2009-12-14 17:22

Re: Stopping music/media player when headset unplugged
 
No, this only sets the media player volume to 0. It doesn't affect the "master" volume setting, so your phone rings normally.

adolfotregosa 2009-12-15 02:27

Re: Stopping music/media player when headset unplugged
 
hi guys.

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. Any ideas ?? thank you.

thp 2009-12-15 08:36

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

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

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

aspidites 2009-12-15 09:08

Re: Stopping music/media player when headset unplugged
 
Would libplayback (com.osso.Playback.Manager in particular) help in this instance? From what I gather, it helps facilitate media playback from multiple sources.

I'm not yet familiar with dbus or even the maemo platform for that matter, so I wouldn't be able to submit a patch. However, if I understand correctly, this would at least prevent you from having to write duplicitous code (mplayer, default media player, etc).

Also, i don't even know if libplayback is available for maemo 4. I saw reference to it while browsing the maemo 5 documentation, so excuse my ignorance if it doesn't exists ;-)

Edit:
[Insert Foot In Mouth]
Further investigation shows that it is in fact a fremantle-only library: http://maemo.org/packages/view/libplayback-1-0/
[/Insert Foot In Mouth

At least this may be the way to go for doing something similar in Maemo 5.

Anyways, I do think this is a cool application, even if I can't currently use it. Keep up the good work!

qwerty12 2009-12-15 09:13

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

Originally Posted by thp (Post 428597)
If you send me some a2dp hardware, I can try to implement it :p

Somebody, be cheap and send him a dbus-monitor --system log instead :p

silvermountain 2009-12-17 08:16

Re: Stopping music/media player when headset unplugged
 
I think I found a bug.

If you play something in mPlayer (say a movie) and pause it and play something in Gpodder-Panucci and then pull out the headphones...the mPlayer starts playing through the speakers.

thp 2009-12-17 10:52

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

Originally Posted by silvermountain (Post 431520)
I think I found a bug.

If you play something in mPlayer (say a movie) and pause it and play something in Gpodder-Panucci and then pull out the headphones...the mPlayer starts playing through the speakers.

Yes, this is because for "Media Player" and "MPlayer", headphoned can only send a "Pause" signal, but this is just like a press on the "Play/Pause" button (i.e. when it's paused, unplugging unpauses the playback). This even happens when you don't have Panucci running.

The only application that provides a "Pause if it's playing, do nothing otherwise" command is Panucci (for obvious reasons ;). At least I have not found D-Bus calls for pausing the media player or input commands for MPlayer that do what I want. An alternative would be to have headphoned go check by itself if Media Player / MPlayer are currently playing something back and avoid sending the "Pause" signal in certain cases.

Again, the code is open and patches are welcome ;)

josetaza 2009-12-30 09:42

Re: Stopping music/media player when headset unplugged
 
hi there,

I did some dbus-monitoring on the N900 and found that the following command pauses the media player:
dbus-send --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.renderer.pause

I made (a quick) change in headphoned and it works.

I also tried with libplayback, but didn't succeed. I think that library should be used when you are creating your own player and is not really for controlling other players. Anyway, that is just my guess, because I can't get much from the documentation...

thp 2010-01-01 14:36

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

Originally Posted by josetaza (Post 446379)
I did some dbus-monitoring on the N900 and found that the following command pauses the media player:
dbus-send --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.renderer.pause

I made (a quick) change in headphoned and it works.

Great! Can you send a patch, so I can merge it into the repository? (commit your changes, then git format-patch + send the resulting files) Don't forget to set your name and e-mail in Git before committing, so that you are properly credited for the commits you do. Thanks :)

DaSilva 2010-01-01 14:59

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

Originally Posted by thp (Post 395566)
The N900 maintains two different volume levels (for plugged and unplugged headphones), so to avoid public transport situations, you just have to unplug your headphones, set the volume to zero, plug them in again, and set your preferred volume. Whenever the headphones get unplugged, the volume will be muted, and when they are reconnected, the volume will be restored.

That said, there might be a use case for having headphoned the N900 as well, just have not got around to do it, as the volume feature described above fixes public transport situations for me already ;)

This is not the same as pause because if you want to use the speakers later you have to turn up the volume again...
So it would be really nice if headphoned could be available for Fremantle, too.


All times are GMT. The time now is 00:33.

vBulletin® Version 3.8.8