Reverse video texture playback with input event using .setTime()

Hi all

New to the world of Code, so forgive my noob questions

Id like to control the playback of a video texture with some keyboard input events
Im adding values to video.setTime() to advance the video’s playback
and subtracting values to video.setTime() to reverse the video’s playback

This works fine when adding/advancing the playback, but when subtracting to reverse the video, the playback jumps around and becomes very laggy.

Any idea what the issue is and is there a better way to set this up?

Thanks, any comments are appreciated :slight_smile:


from panda3d.core import loadPrcFileData
from panda3d.core import WindowProperties
from panda3d.core import LPoint3, LVector3
from panda3d.core import VideoTexture
from direct.showbase.ShowBase import ShowBase
from direct.task.Task import Task

confVars = """

win-size 1280 720
window-title test

loadPrcFileData("", confVars)

keyMap = {
    "forward" : False,
    "reverse" : False

def updateKeyMap(key, state):
    keyMap[key] = state

class MyGame(ShowBase):
    def __init__(self):

        sphere = self.loader.loadModel("models/sphere.obj")
        self.videoTex = loader.loadTexture("videos/drone.mp4")


        taskMgr.add(self.controlVideo, "controlVideo")

        self.accept("w", updateKeyMap, ["forward", True])
        self.accept("w-up", updateKeyMap, ["forward", False])
        self.accept("s", updateKeyMap, ["reverse", True])
        self.accept("s-up", updateKeyMap, ["reverse", False])
        self.speed = 1.0
    def controlVideo(self, task):
        dt = globalClock.getDt()
        pos = self.videoTex.getTime()
        if keyMap["forward"]:
            pos += self.speed * dt
        if keyMap["reverse"]:
            pos -= self.speed * dt

        self.last = task.time
        return Task.cont

game = MyGame()

Hmm… I haven’t really worked much with this, but I wonder whether it’s not a result of the backwards seeking interfering with the forwards playback. What happens if you pause the video while seeking backwards, and only resume it once no longer seeking?