View Single Post
m2cm2c's Avatar
Posts: 100 | Thanked: 240 times | Joined on Feb 2010 @ The South Pole O.o
#1
Hi,

I've made a simple python script to skip to the next track when you shake the phone

heres what you have to do:
extract the script to your phone
open the media player and start playing music

open the terminal and:
cd to the directory of the script
type in:
python skipshake.py



shake the phone and see the results
when you're done with the script close the terminal.



here is the script:
Code:
import gobject
import dbus
import dbus.glib
import pygtk
import gtk, math, os, time
from dbus.mainloop.glib import DBusGMainLoop
class Table:
	def __init__(self):
		dbus_loop = DBusGMainLoop()
		self.bus = dbus.SystemBus(mainloop=dbus_loop)
		go=0
		margin = 500
		while True :
			rawMceRequest = self.bus.get_object("com.nokia.mce", "/com/nokia/mce/request")
			self.mceRequest = dbus.Interface(rawMceRequest, dbus_interface="com.nokia.mce.request")
			orientation, standState, faceState, xAxis, yAxis, zAxis = self.mceRequest.get_device_orientation()
			if go==1:
				if abs(current) > abs(yAxis)+margin:
					self.roger(abs(yAxis))			
			current=yAxis
			time.sleep(.25)
			go=1
	def roger(self,a):
		i=0
		shake_list=range(100)		
		print "+-+-+-+-+-+-"		
		while i<100:
			orientation, standState, faceState, xAxis, yAxis, zAxis = self.mceRequest.get_device_orientation()
			shake_list[i]=(int(yAxis))
			i+=1
		z=sorted(shake_list)
		slope= [y - x for x, y in zip(z[:-1], z[1:])]
		print"current slope (",sum(slope)/99,")"
		if sum(slope)/100 > 35:
			os.popen("dbus-send --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.renderer.next")
			print "skipped track at a slope of",sum(slope)/99
def main():
	gtk.main()
	return 0       
if __name__ == "__main__":
    Table()
    main()

please test it out and tell me what you think about it
Attached Images
 
Attached Files
File Type: gz skipshake.py.tar.gz (771 Bytes, 155 views)

Last edited by m2cm2c; 2010-03-12 at 15:31. Reason: cleaned the script a little
 

The Following 7 Users Say Thank You to m2cm2c For This Useful Post: