Reply
Thread Tools
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#11
This should be fairly simple (a few lines of python) so that when it received a dbus charging off it would emit a media pause event, and charging would push play, however it would start when you plugged it in even if you never pressed play.
 
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#12
Horridly cobbled hack (os.system dbus send is a one-line but I should use Python to emit the signal).

With the media player, it does exactly what was described. When the charger is on (providing voltage) it does a "play", when the voltage is lost or the charger is disconnected, it does a "pause".

Code:
#!/usr/bin/env python2.5

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

import dbus
import gobject
import os

class bthssetup():
    def __init__(self):

        self.m_loop = DBusGMainLoop()
        self.bus = dbus.SystemBus(mainloop = self.m_loop, private = True)

        self.bus.add_signal_receiver(self.discharge,signal_name = "charger_disconnected",
                                     dbus_interface = "com.nokia.bme.signal",
                                     path = "/com/nokia/bme/signal" )
        self.bus.add_signal_receiver(self.charge ,signal_name="charger_connected",
                                     dbus_interface = "com.nokia.bme.signal",
                                     path = "/com/nokia/bme/signal" )

    def charge(self,sender=None):
        os.system('dbus-send --dest=com.nokia.osso_media_server /com/nokia/osso_media_server com.nokia.osso_media_server.music.play')

    def discharge(self,sender=None):
        os.system('dbus-send --dest=com.nokia.osso_media_server /com/nokia/osso_media_server com.nokia.osso_media_server.music.pause')
        
#------------------------------------------------------------------------
    def run(self):
        dbus_loop = gobject.MainLoop()
        dbus_loop.run()

if __name__ == "__main__":
    app = bthssetup()
    app.run()
 

The Following User Says Thank You to tz1 For This Useful Post:
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#13
The above is a variant of the bluetooth or normal headset button control scripts others have done, but with an event listener for the charger events instead of the button press.

Feel free to improve it (and explain how to install Python though it should already be there with Canola if I remember right).
 
Posts: 6 | Thanked: 2 times | Joined on Jan 2009
#14
Uhh...ohh... I'm stunned.
So it should work with that..?
 
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#15
Copy the text in the box (which is a python program) and paste it into a file on the tablet.

Then in an xterm do "python <filename>" or use something like osso cpu statusbar to launch it. I don't have time at the moment to package it (or create a universal play/pause app that would use the bluetooth switch, headset switch, and the charger or something). If someone else is interested, please run with it.

(I've wanted something like this since my car/motorcycle audio also shuts down when I turn off the ignition so having a pause/resume is nice so it probably isn't dead, I'm just extremely busy)
 
Posts: 118 | Thanked: 59 times | Joined on May 2007
#16
Rather than starting another thread, I hope it's appropriate to offer a shell script to address the same situation, but NOT with Canola. This script does the same pause/unpause operation, but using XMMS and its command-line controller, xmmsctrl. It also addresses the issue that volume is automatically reduced when you plug into the audio output (headphone) jack, usually helpful behavior if phones are being plugged in, but not when using the tablet as an audio source for another device. (The cure was posted by Benson, here: http://www.internettablettalk.com/fo...4&postcount=10 )

Code:
#!/bin/sh
#Use Internet Tablet with XMMS as car stereo source
#pauses when external power is removed; rewinds 10 seconds & resumes play when restored
#sets system master volume to 100 when output jack is connected/disconnected
#requires xmms and xmmsctrl
#tested on N800 with OS2008 5.2008.43-7, bash2

dbus-monitor --system "member='charger_connected'" > charge_on.txt &
dbus-monitor --system "member='charger_disconnected'" > charge_off.txt &
dbus-monitor --system "path='/org/freedesktop/Hal/devices/platform_headphone'" > phone_plug.txt &

if xmmsctrl running
then
	xmmsctrl play
else
	xmmsctrl launch
	xmmsctrl play
fi

sleep 3

#flush initial messages
echo > charge_on.txt
echo > charge_off.txt
echo > phone_plug.txt
gconftool -t int -s /apps/osso/sound/master_volume 100

#continue monitoring until xmms is terminated
while `xmmsctrl running`
do
	chargeon=`wc -c charge_on.txt | cut -b1-10`
	chargeoff=`wc -c charge_off.txt | cut -b1-10`
	phoneplug=`wc -c phone_plug.txt | cut -b1-10`
	if [ "$chargeoff" -gt 1 ]
	then
		xmmsctrl pause
		echo > charge_off.txt
	elif [ "$phoneplug" -gt 1 ]
	then
		gconftool -t int -s /apps/osso/sound/master_volume 100
		echo > phone_plug.txt
	elif [ "$chargeon" -gt 1 ]
	then
		if xmmsctrl paused
		then
			xmmsctrl time -10
			xmmsctrl play
		fi
		echo > charge_on.txt
	fi
	sleep 3
done

#following line kills all running dbus-monitor processes; comment out if any in use besides the 3 in this script
killall dbus-monitor
Be aware that I make no claims of programming skill! This script works on my tablet and appears not to have damaged anything... yet! I can't guarantee that your experience won't turn out to be different.

Corrections are welcome. I'm sure there are better ways to acomplish this.
 
Reply


 
Forum Jump


All times are GMT. The time now is 17:54.