Synchronizing newVideo position to ScrollView?

Pretty general question here from a newbie who’s crafted his beginning code so far by pillaging from a bunch of great samples. I’ve got a scrolling field / background working fine and draggable nicely with touch interaction. I’ve also added an mp4 movie (video = newVideo()) which I guess just floats on top due to being native and thus isn’t really a part of the scrollView like everything else (which would be the preferred case, but is, I guess, a limitation of newVideo()?). I can almost compensate for this by simply checking the position of the scrollView in my scrollListener (getContentPosition()) and updating the video.y position to match any changes in the scrollView.

The problem is friction. If I don’t reduce the friction to zero (which is not as elegant/smooth), the scrollListener only generates events while the finger is dragging the scrollView (“moved”) and then when it finally comes to final rest position (“stopped”). So the video doesn’t update while the scroller is “drifting.”

There might be a better way to do this whole thing. I may be approaching the problem strangely. I could use a massive sprite sheet instead but an mp4 is quite a bit more efficient, size-wise and control-wise. (I’m basically seeking the proper frame in the video to give me a parallax view in the “window” that is the video. If that makes sense.) But right now I can only update the position and frame of the video when I get an event back from the scrollListener, and there doesn’t seem to be an event when the position is simply changing based on “drift” and non-zero friction. (At least not until it finally comes to rest.) How (or where) could I get a “changed position” event, or what other method should I use to update the video position to keep it in sync with the scrollWindow? (Other than checking this all the time in a main loop or something.)

Alternate techniques welcome. Could easily be going about this arse-backwards.

Thanks,
z

P.S. Really hard to know which category to post this to. Audio and Graphics? As a recent Newbie, I’ll put it there, but man that’s a lot of categories to choose from… :slight_smile:

There are probably many ways to solve this, but here is one way I came up with:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2020/05/videoScrollerHelp.zip

Run the demo and see how it behaves, then take a look at the code. I didn’t add a video object because I use Windows as my main dev env and newVideo() is not supported on windows. That said, the concept is the same for my ‘fake’ video object.

1 Like

Thanks, Roaming! That looks fantastic. (And simple!)

Will adapt to my code shortly and follow up with any difficulties, but this looks like it should do it! Thanks so much for the quick reply and sample code!

z