Active Topics

 



Notices


Reply
Thread Tools
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, 143 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:
Posts: 755 | Thanked: 406 times | Joined on Feb 2008 @ UK
#2
Haven't tried this (or the other), but check out shake2control.
 
m2cm2c's Avatar
Posts: 100 | Thanked: 240 times | Joined on Feb 2010 @ The South Pole O.o
#3
Originally Posted by codeMonkey View Post
Haven't tried this (or the other), but check out shake2control.
hey

I've seen that one, but it is in C and it is a bit more complex than this python script.

cheers
 

The Following User Says Thank You to m2cm2c For This Useful Post:
Posts: 2,014 | Thanked: 1,581 times | Joined on Sep 2009
#4
Does this check the prox sensor for being covered before skipping the track (I am no expert in python but didnt see anything suggesting it did). I prefer if it doesnt since I keep my n900 in its case most times.
__________________
Class .. : Power Poster, Potential Coder
Humor .. : [*********] Alignment: Chaotic Evil
Patience : [***-------] Weapon(s): +2 Logic Mace
Agro ... : |*****-----] Relic(s) : G1, N900

 
m2cm2c's Avatar
Posts: 100 | Thanked: 240 times | Joined on Feb 2010 @ The South Pole O.o
#5
Originally Posted by Bratag View Post
Does this check the prox sensor for being covered before skipping the track (I am no expert in python but didnt see anything suggesting it did). I prefer if it doesnt since I keep my n900 in its case most times.
well I made this script so I can change the track even if it is inside the n900 cover, say I'm transmitting a FM station to my car, I don't want to take it outside the cover to get it working,

also this script is pretty smart when it gets to shaking the phone, I didn't encounter any random track changes yet

try it out and tell me what you think.
 
Posts: 2,014 | Thanked: 1,581 times | Joined on Sep 2009
#6
Originally Posted by m2cm2c View Post
well I made this script so I can change the track even if it is inside the n900 cover, say I'm transmitting a FM station to my car, I don't want to take it outside the cover to get it working,

also this script is pretty smart when it gets to shaking the phone, I didn't encounter any random track changes yet

try it out and tell me what you think.
Groovy - Getting the pgone out of its case to go to the next track was always a potential crash hazard for me Will check the script and let you know.
__________________
Class .. : Power Poster, Potential Coder
Humor .. : [*********] Alignment: Chaotic Evil
Patience : [***-------] Weapon(s): +2 Logic Mace
Agro ... : |*****-----] Relic(s) : G1, N900

 
Posts: 4,556 | Thanked: 1,624 times | Joined on Dec 2007
#7
hmm doesn't seem to work for me. it just displays changes in slope level when i move and shake the N900.
__________________
Originally Posted by ysss View Post
They're maemo and MeeGo...

"Meamo!" sounds like what Zorro would say to catherine zeta jones... after she slaps him for looking at her dirtily...
 
Posts: 88 | Thanked: 28 times | Joined on Feb 2010 @ Hyderabad, India
#8
Originally Posted by Laughing Man View Post
hmm doesn't seem to work for me. it just displays changes in slope level when i move and shake the N900.
Yeah same with me! just echoes some slope
 
m2cm2c's Avatar
Posts: 100 | Thanked: 240 times | Joined on Feb 2010 @ The South Pole O.o
#9
Originally Posted by Laughing Man View Post
hmm doesn't seem to work for me. it just displays changes in slope level when i move and shake the N900.

Originally Posted by avinashsonee View Post
Yeah same with me! just echoes some slope
yea it should show you a slope, but it won't change the track if the slope is less than 35, you can change that from the script.

to get a higher slope you'll need to be shaking it for a bit longer
if you change the setting of the slope to a lower value, it'll change the track if you shake it less. but 35 is the best value I came up with since it makes sure you've shaken it enough.

if you get the message:
skipped track at a slope of some_number
that means that the player should've skipped the track

if it did display "skipped track at a slope of some_number" but didn't change the track, then please tell me so.


feel free to explore the script and play with it as much as you want


cheers ^^

Last edited by m2cm2c; 2010-03-11 at 22:24.
 

The Following User Says Thank You to m2cm2c For This Useful Post:
m2cm2c's Avatar
Posts: 100 | Thanked: 240 times | Joined on Feb 2010 @ The South Pole O.o
#10
To make things clearer about the slopes, I've collected some data from previous shakes and plotted them with pygame
here you go
Attached Images
 
 

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


 
Forum Jump


All times are GMT. The time now is 20:12.