I am trying to play a single video multiple times (for exemple each time a key is pressed) and at random <X;Y> positions…
That much I can do.
But
the new ofVideoPlayer clone must restart the video. and I realized that all ofVideoPlayer clones are playing each video at the same position. which means that even if I press keys with delay all videos will end simultaneously.
you shouldn’t clone the video player like that just create a new one by loading the movie again. What you are doing there is just creating a new reference to the original.
That won’t make any difference. The file isn’t really loaded all at once so the only difference between having only one file opened would be minimal, only the number of file handles would change which is really not important in something like this
The only thing that can be slower in something like this is that the initial loading can be slower than using a video that is already loaded.
One way to alleviate the problem is to use loadAsync instead of load to avoid at least blocking the main thread and possible stuttering if the block takes longer than one frame
Another way if that’s not enough is to have a pool of video grabbers as crystem suggests. Even if you don’t know how many times the key is going to be pressed there’ll be a maximum that makes sense, mostly cause more than that will be to much to handle in terms of performance but even in terms of how much you can show in the screen. So you ca just preload as many videos and not update them until they are active. Once you have used all of them just reuse the first one that was activated for the new one
In any case don’t try to optimize until it’s really needed, if just calling load or loadAsync is fast enough trying to optimize it further will only make your project more complicated and error prone