How to have ofVideoPlayer play a short snippet of video?

Say, I have a video 1 minute long, but when I press a button, I’d like the stream to seek to 0.3 seconds, and play a short duration of 0.4 seconds (so, play the snippet in the 1-minute video which is between the 0.3 sec and 0.7 sec marks), and then stop/pause.

I am looking at http://openframeworks.cc/documentation/video/ofVideoPlayer/ - and I can see there are methods .play(), .stop() and .setFrame(int frame) and .setPosition(float pct) “Sets the position of the playhead to a given percentage through the movie.” - so, no settings in time directly, but I’m OK with either frames or percent of movie file.

So, I can seek, I can tell the video to play - but how can I tell it that it should stop automatically after, say, 0.4 seconds?

Store the time when you press the key to start the video player, and wait for X milliseconds and then stop it:

Basically, to get you started - one idea:
startTime = ofGetElapsedTimeMillis(); // I.E store this once when you press ‘play’

if (ofGetElapsedTimeMillis() - startTime > 1000) (myVideoPlayer.stop() );

1 Like

Thanks for that, @steeley :

Yeah, that makes sense - thanks for noting this!