ofVideoPlayer.load blocking thread?

Hi,

I’m trying to load a video and set a random frame to start it within the update() function:

                video[activeVideoPlayer].load(videoDir.getPath(activeVideo));
                int frames = video[activeVideoPlayer].getTotalNumFrames();
                video[activeVideoPlayer].setFrame( ofRandom(frames) );
                video[activeVideoPlayer].play();

The loading and playing works fine, but I get quite a lot of unable to seek type of errors, which sets the video to play from the first frame. Is there a way (besides inserting ofSleepMillis()) to make the .getTotalNumFrames() wait until the loading of the file is complete without disrupting another video playing at the same time?

As always, grateful for any help!
Kenneth

Hey Kenneth @kflak1,

You could have a look at loading a video file into an ofVideoPlayer in a separate, dedicated thread with the ofThread class, provided that you have an extra one to work. An ofThread can run outside of the main thread, so your app doesn’t have to pause while the video file loads. Once the ofThread has finished loading the file, the ofVdieoPlayer could be stored in a std::vector (I think), which might be easier and safer than using a C-style array to contain them.

There are some examples in the folder for using the ofThread class. Also, there is an ofBook chapter about threads here: ofBook - Threads. The documentation for the class has a nice, basic description of how to use it: ofThread | openFrameworks. Also maybe have a look too at the ofxThreadedImageLoader for a class with a similar type of functionality.

Thanks! I was already trying to wrap my head around how to do this in a separate thread, and have been using ofThread for a simple kind of timeline as well. Will take a look at how it’s done in the image loader class.

K