Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop & pause precision bug #49

Closed
IsraelThompson opened this issue Jul 13, 2011 · 2 comments
Closed

stop & pause precision bug #49

IsraelThompson opened this issue Jul 13, 2011 · 2 comments
Assignees
Milestone

Comments

@IsraelThompson
Copy link

Former "Limit Playcount / Delay Closing / Callback Function / Oh my! Oh my!"

This is sort of a hybrid post as it's a bit of a start to an improvement, but there are questions in involved, and this might also entail feature requests :)

Anyway, I'm using your reel (exclusively) on the index page of a site I'm building to showcase any assortment of random dynamic reels. So here's what happens (or what I want to happen) on my page:

  1. Upon page load, my code randomly chooses a reel to play.
  2. The reel is initiated and plays the reel specified.
  3. I play the reel any number of designated times I specify depending on the item selected to play.
  4. The reel pauses or delays for a "closing" time that I specify (again, depending on the movie).
  5. Once the item comes to the end of it's playcount, your script initiates a callback looking for a function that I have waiting in my window. My function initiates a teardown and reuses the same div and img tag as it's staging area to play the next randomly selected reel.

Forgive me if I missed this, but I didn't see answers or solutions to some of this already, so I began to tinker around in your reel code and was able to come up with a fix for my own needs, so I'd like to share that, but still need help with a few caveats.

First, in your file "jquery.reel.js", I added a few lines. My version can be found at the following URL, but I'll quickly point out the changed lines below:

http://israelthompson.com/dl/DIG/www/js/jquery.reel.js

Lines 101-103 I added:

  playcount:       null, // how many times to play the movie (leave null to loop infinitely)
  framestopAdj:       0, // adjustment of when  to stop the frames (if playcount and frames are specified)
  closing:            0  // closing in milliseconds (if ending the movie at specified playcount)

Lines 136-138 I added:

var playcount=0, framecount=0, framestotal=0, framestop=0;
if (opt.playcount > 0 && opt.frames > 0) { framestop = (opt.playcount * opt.frames) - opt.framestopAdj }
if (opt.closing > 0) { var closing = opt.closing };

Lines 554-573 I added:

if (frame != was) { // count each new frame
    //alert(opt.playcount)
    if (framecount == opt.frames) { // played the reel to the end
        playcount++;
        alert('played:' + playcount + '\ncurrent frames:' + framecount + '\ntotal frames:' + framestotal + '\nstop frame:' + framestop + '\nclosing delay:' + closing)
        framecount = 0;
    }
    if (framestotal == framestop) {
        alert('stop!!');
        t.trigger('stop');
        if (window.reelCallback) { reelCallback() }
    } else if (opt.playcount > 0 && playcount == opt.playcount) { 
        alert('stop!!'); 
        if (window.reelCallback) { reelCallback() }
        t.trigger('pause');
        t.trigger('stop');
        //t.trigger('teardown');
    }
    framecount++; framestotal++
}

So, my fix:

Since I couldn't figure out how or where you have provisions to tell exactly how many times the movie or reel had played or exactly when it reached the end (regardless if it's looping, running cw, or has a rebound set) or had played once, so I could stop it at any playcount I desired... I found your frames code and began to tinker.

Once I figured out how to count frames (lines 550'ish+), I then was easily able to distinguish when my movie had played.

I'm not sure if counting frames, helps everyone who uses your script, though, since I saw in your code that there were instances for rows and other types of movies. Perhaps this is a start though?

After counting frames, I then fed your script a set playcount (line 101) to get it to stop at the end. And, to actually stop the movie, I added a stop on line 563, and initiated a callback to a function I had waiting on line 564.

PROBLEM!

All of this seems to work fairly well, but I ran into a problem right off the bat with different movies and using the t.trigger('stop') and t.trigger('pause') functions at the exact frame I wanted to stop at.

I noticed that ('stop') didn't actually stop right at the frame that it was supposed to... It always went a frame or two longer then finally stopped. It seemed very precise too, depending on the movie, so I came up with a workaround for that, which I added to line 102. Also, line 136 is part of this... With this, I was able to offset the frames I was expected to play the movie, by a specified digit and initiate the t.trigger('stop') function a frame or two early. Works well, so far...

So one of my questions, is this... Is there a reason the pause and stop don't actually stop right at the frame? Is there something I can do differently to solve this?

Also, once the matter of pause/stop delay are solved, I'd love to finalize my "closing" addition I started on... I was figuring on adding a simple set timeout function based off a supplied integer (per movie) , but when tested, this is when I noticed the t.trigger('pause') function is even worse delayed than the stop function. There was no way to accurately "pause" the movie at an exact frame, then set a timeout before initiating a stop and invoking my callback.

My testing page can be seen here (with alerts between playcounts):

http://israelthompson.com/dl/DIG/www/gridinator/gridinator-perc.php

And a page that is already making use of my fixes (without the closing pause feature and no alerts) can be seen here:

http://israelthompson.com/dev/DIG/www/

Any help is appreciated, and again, please forgive me if I'm asking questions regarding matters that have already been covered.

Izz

@IsraelThompson
Copy link
Author

It's been a while and haven't heard anything... Hope all is well :)

@ghost ghost assigned pisi Nov 1, 2011
pisi added a commit that referenced this issue Dec 23, 2011
…stop"` event is triggered, Reel stops on the spot. #49

It creates a animated Reel and waits for the target reference frame. Once the frame is reached it checks if it really stopped and asserts the correct target frame. It then waits longer than the `delay` and double-checks it's not playing even then.
pisi added a commit that referenced this issue Dec 23, 2011
Basically the same as the one for `"stop"`. It waits longer than the `delay` and asserts the playback has resumed.
@pisi
Copy link
Owner

pisi commented Dec 23, 2011

Hey Izz,

first I'm supper sorry it took me so long to respond on this issue. Please apologize my insufficience.

Now to the issue. I've read it carefully several times and was able to pull two main issues out from it:

  1. the closing animation in similar fashion as the opening one - no doubt that, cool feature suggestion! Let's extract it from this issue into its own Possibility of a closing animation #90
  2. you experience some sort of bug in precision of "pause" and "stop" events.

I actually don't know about 1.1.3, but the 1.1.3-devel performs flawlessly in the tests I've created to get some insight and confidence. The tests are available in the dedicated 49-start-stop-precision branch. Any test adjustments to better fit your case are always welcome.

So theoreticaly, if the error isn't in your particular setup (which I seriously doubt) and is indeed a bug in 1.1.3, the good news for you is that in the upcoming 1.2 this bug/issue is no more and the closing animation should be able to do without the adjustment.

Happy holidays, mate!

@pisi pisi closed this as completed Dec 23, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants