maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [SOLVED]Bluetooth Headset Button to pause/play Canola/Mplayer (https://talk.maemo.org/showthread.php?t=22370)

ericcmi 2008-07-29 00:31

[SOLVED]Bluetooth Headset Button to pause/play Canola/Mplayer
 
Here it is.
This python script will pause and play both mplayer and canola(and probably others) regardless of whether or not the media player is the active window(i.e. can be minimized.)

The main bit of the script is from http://www.bitsmithy.net/.
The other bit is from qwerty12 from this thread.

1. Copy this code to a file.
Code:

#!/usr/bin/env python2.5

from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

import dbus
import gobject
import os

dbus_loop = gobject.MainLoop()
bus = dbus.SessionBus()

def on_button_pressed (sender=None):
    os.system('dbus-send --dest=com.nokia.osso_media_server /com/nokia/osso_media_server com.nokia.osso_media_server.music.pause')
   

headset = bus.get_object('com.nokia.osso_hp_ls_controller', '/com/nokia/osso_hp_ls_controller')
headset_iface = dbus.Interface(headset, dbus_interface='com.nokia.osso_hp_ls_controller.headset')
headset_iface.connect_to_signal('button_pressed', on_button_pressed, sender_keyword='sender')

dbus_loop.run()

2. Copy that file to the device.
3. cd to directory you copied to.
'cd /media/mmc1'
4. in console type:
Code:

python filename.py
filename.py = whatever you named the file you copiedthe script into.

This should work. python was installed with canola for me i believe. Should not be to difficult to get it if you dont have it.

Im working on a solution to have the on_button_pressed function use python to send the pause method rather than use the commandline way with os.system. If you can get it working that way, please do. Then please be sure to post it back here for everyone to enjoy.

Eric

antikx 2008-07-29 03:17

Re: [SOLVED]Bluetooth Headset Button to pause/play Canola/Mplayer
 
thanks for posting the script
when I run it I get this:
process 4498: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.
D-Bus not built with -rdynamic so unable to print a backtrace
Aborted

qwerty12 2008-07-29 10:44

Re: [SOLVED]Bluetooth Headset Button to pause/play Canola/Mplayer
 
I'd be interested in seeing what you can do as I'd be interested in replacing the dbus-send command with the proper python dbus commands.

Have you thought about looking into daemonising it like I do with headset-control?

Btw, replace:
os.system('dbus-send --dest=com.nokia.osso_media_server /com/nokia/osso_media_server com.nokia.osso_media_server.music.pause')

with:
os.system('run-standalone.sh dbus-send --dest=com.nokia.osso_media_server /com/nokia/osso_media_server com.nokia.osso_media_server.music.pause')

antikx 2008-07-31 13:36

Re: [SOLVED]Bluetooth Headset Button to pause/play Canola/Mplayer
 
thanks qwerty12, running it as non-root did the trick.

qwerty12 2008-07-31 13:47

Re: [SOLVED]Bluetooth Headset Button to pause/play Canola/Mplayer
 
Oh, you saw? :)

I edited with the run-standalone stuff because using run-standalone lets you run it as root or non-root.


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

vBulletin® Version 3.8.8