maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   N900 play next music track when you shake the phone (python script) (https://talk.maemo.org/showthread.php?t=47128)

m2cm2c 2010-03-11 15:41

N900 play next music track when you shake the phone (python script)
 
2 Attachment(s)
Hi,

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

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

codeMonkey 2010-03-11 15:51

Re: N900 play next music track when you shake the phone (python script)
 
Haven't tried this (or the other), but check out shake2control.

m2cm2c 2010-03-11 15:58

Re: N900 play next music track when you shake the phone (python script)
 
Quote:

Originally Posted by codeMonkey (Post 563892)
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 :D

Bratag 2010-03-11 16:16

Re: N900 play next music track when you shake the phone (python script)
 
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.

m2cm2c 2010-03-11 16:33

Re: N900 play next music track when you shake the phone (python script)
 
Quote:

Originally Posted by Bratag (Post 563936)
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.

Bratag 2010-03-11 16:42

Re: N900 play next music track when you shake the phone (python script)
 
Quote:

Originally Posted by m2cm2c (Post 563969)
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.

Laughing Man 2010-03-11 17:43

Re: N900 play next music track when you shake the phone (python script)
 
hmm doesn't seem to work for me. it just displays changes in slope level when i move and shake the N900.

avinashsonee 2010-03-11 18:33

Re: N900 play next music track when you shake the phone (python script)
 
Quote:

Originally Posted by Laughing Man (Post 564075)
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 2010-03-11 22:20

Re: N900 play next music track when you shake the phone (python script)
 
Quote:

Originally Posted by Laughing Man (Post 564075)
hmm doesn't seem to work for me. it just displays changes in slope level when i move and shake the N900.


Quote:

Originally Posted by avinashsonee (Post 564127)
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 ^^

m2cm2c 2010-03-12 00:17

Re: N900 play next music track when you shake the phone (python script)
 
1 Attachment(s)
To make things clearer about the slopes, I've collected some data from previous shakes and plotted them with pygame
here you go :D

m2cm2c 2010-03-12 15:32

Re: N900 play next music track when you shake the phone (python script)
 
I've cleaned up the script a little :)

avinashsonee 2010-03-12 15:51

Re: N900 play next music track when you shake the phone (python script)
 
Yeah, it works. nice :)

Erazor 2010-12-10 10:45

Re: N900 play next music track when you shake the phone (python script)
 
thx for the nice app :D

if sum(slope)/100 > 35:
i edit the 35 to 5

and all works well XD

thx thx


Greetz
Erazor


All times are GMT. The time now is 21:14.

vBulletin® Version 3.8.8