PDA

View Full Version : My mod to digitalhigh's Seekbuttons.m script isn't quite working


MikeHunt79
19th March 2004, 12:38
I got this script from frisbeemonkey's exellent site. I needed it to just seek within a song, and not change tracks, so I set about changing it. I thought... why not change the script so when a single click is performed on the button, it skips 5 seconds instead of the whole song. Here's my mod:


#include </lib/std.mi>

// declarations
global button back, forward;
global int b1, b2, p1, p2, a1, a2;
global timer buttontimer1, buttontimer2;
global group pgroup;
global boolean time1, time2;


system.onscriptloaded() {

pgroup = getscriptgroup(); //finds the group the buttons are in.

back = pgroup.findobject("previous"); //finds our buttons
forward = pgroup.findobject("next");

buttontimer1 = new timer; //makes the timers and sets their delay
buttontimer1.setdelay(1);

buttontimer2 = new timer;
buttontimer2.setdelay(1);

} //ends the onscriptloaded command


system.onscriptunloading() {

delete buttontimer1;
delete buttontimer2;

}


back.onleftbuttondown(int x, int y) {
buttontimer1.start(); //starts the timer when you click down

}


back.onleftbuttonup(int x, int y) {
buttontimer1.stop(); //stops the timer
if (time1==0) { //checks to see if you've held the button down long enough

p1=System.getposition(); //gets the current song position
p1-=5000; //sets the position back 5000 frames (5 secs)
system.seekTo(p1); //seek backwards
time1=0; //resets the counter
}

B1=0; //sets the timer back to 0
a1=100; //sets the seek speed back to 100

}

forward.onleftbuttondown(int x, int y) {
buttontimer2.start();

}


forward.onleftbuttonup(int x, int y) {
buttontimer2.stop();
if (time2==0) {

p2=System.getposition(); //gets the current song position
p2+=5005; //sets the position forwards 5000 frames (5 secs)
system.seekTo(p2); //seek forwards
time2=0; //resets the counter
}

b2=0;
a2=100;

}

buttontimer1.ontimer() {

if (b1>=10) { //checks to see if counter at bottom has reached 50 ms yet
time1=1; //flag for the onbuttonup command so it knows what to do
p1=System.getposition(); //gets the current song position
p1-=a1; //sets the position back by a1, which is currently 100
a1+=50; //adds 50 to it, so the seekspeed increases
if (p1<=0) { //if we get to the end of the song
System.previous(); //skip to the previous song
a1=100; //resets the seeksepeed to 100 again
p1=((System.getPlayItemLength() * 1000)-1); // gets the length of the song and goes to the end
system.seekto(p1);//starts seeking back again
system.play(); //triggers the play command to show the new song
} else {
system.seekTo(p1); //otherwise, seek backwards
}
}

b1+= 1; //adds one to the counter
}

buttontimer2.ontimer() {

if (b2>=10) {
time2=1;
p2=System.getposition();
p2+=a2;
a2+=50;
if (p2>=System.getPlayItemLength() + 5) {
System.next();
a2=100;
p2=(0);
} else {
system.seekTo(p2);
}
}
b2+=1;
}


The problem is that this is unreliable at best... the single-click skip-5secs-forward hardly ever works, but the one-click 5secs-rewind almost always does... holding down the buttons works fine like the original script however.

What is going on here? I really need to get this sorted.

MikeHunt79
25th March 2004, 02:02
Dont worry, i have sorted this whil the forums were down...