Automatically start Media Player app from head-phone's play button

asked 2014-04-04 15:35:44 +0200

00prometheus gravatar image

updated 2014-07-24 10:29:40 +0200

jiit gravatar image

To use a Bluetooth headset or earphones on the Jolla, you have to take out the phone, manually open Media player, and start the music from the inside the Media player app.

On the N900, when using a Bluetooth headset, I didn't need to take the phone out of my pocket at all. I simply turned on my headset, clicked the headset's play button and music would start playing.

With a wired headset, you would have to take out the phone to plug in the headset, but you wouldn't need to unlock the phone, hunt for the media player app and manually start it. You just plug in the headset, click the button on the headset and music plays.

The N900 function required you to have the Media player controller widget running on your desktop, but it could just as well have been a pure background daemon that kept tabs on the headset buttons and started the Media player when needed.

edit retag flag offensive close delete

Comments

Please add support for apple headphones with remote&mic as well! It's much easier to skip a song or pause by using the buttons on the headset that by whipping out the phone.

kylihars ( 2014-04-05 09:24:57 +0200 )edit

I managed to do something like that with this pythonscript https://github.com/Zer0C001/jolla_headset_button. although i made some modifications to it and used another mediaplayer. the thing is i got the mediaplayer to shuffle all songs after the app loaded, but that didn't work in the background. what i tried was putting the function or whatever this is from the cover qml, which gets invoked when the coveraction for shuffle is pressed, into the onFinished section of i think it was the main qml, but this didn't work in the background, so i used quasar-mx, but i had problems with refreshing the library, after adding an album and after i tried to refresh it manually most of the ~200 songs disappeared and i was left with ~15 so i used deadalus. unfortunately deadalus plays the last playlist from the beginning, so it is always the same song, but if i intentionally close the app i can make shuffle playlist so it is almost the same. it would be nice if it could invoke that function automatically after loading the app. oh another thing, i got the jolla-mediaplayer to play in the background, when i put the shuffle function or whatever outside the onFinished section, but it would play only the first song in the library somehow, because it scans the library only when the jolla-mediaplayer app was active on the screen and then it would take longer as usually, because playback was somehow interfering with it. any tips on triggering the scan after the app started would be appreciated. the changes i made to tmp.py were that after if press_num==0; i put this

                                process_name="harbour-daedalus"
                                tmp = os.popen("ps -Af | grep harbour-daedal").read()
                                print tmp
                                if process_name not in tmp[:]:
                                        os.system('runuser -l nemo -c harbour-daedalus &')

and i commented self.mediaplayer.toggle_pause() with #

smatkovi ( 2018-09-24 11:54:35 +0200 )edit

because this function is already implemented in jolla-mediaplayer and daedalus. quasamx from openrepos doesn't have it it, but the up to date version on the developers homepage has it. change harbour-daedalus to jolla-mediaplayer or harbour-quasarmx-lite if you want to use one of those players. the grep line shouldn't contain the whole name, because grepping shows up in ps and then python thinks the app is already running and doesn't start it. oh and i changed infile_path = to infile_path = /dev/input/event6, i thought this was with the update, but now i'm not sure, because i use oneplus x and maybe it's device related. anyway you can check if any of the events give something in the terminal if you press the headsetbutton with, i believe, cat -f /dev/input/eventx whete x is any number of the event files in that directory.

smatkovi ( 2018-09-24 12:05:17 +0200 )edit

oh and i was too lazy to write a systemd script for the tmp.py daemon so i used appsafterboot from schturman https://openrepos.net/content/schturman/apps-after-boot and edited /usr/share/openrepos-startapps-after-boot/start-afterboot.sh, where i commented the line invoker --type=silica-qt5 -s -n -d 5 /usr/bin/jolla-mediaplayer -fullscreen -url /usr/share/jolla-mediaplayer/qml/mediaplayer.qml in the media section and put the path to tmp.py script in the next line and in settings i activated mediaplayer to start after boot. it takes a few seconds, try it out with notes for instance, it could take up to 30s, or it feels like that.

smatkovi ( 2018-09-24 13:06:39 +0200 )edit

i also asked for help on http://talk.maemo.org/showthread.php?p=1548818#post1548818 just in case^^

smatkovi ( 2018-09-24 13:22:58 +0200 )edit