We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hej –
i know how to play/loop an existing video. but what if i have a folder in which videos will be copied (from an external source – in my case a raspberry pi that uploads captured video clips) dynamically?
can i add videos to my canvas on runtime? there is a function to list folder contents – but i don't know HOW TO dynamically add video sources to a running project.
is there any help? or a definitive "NO" …? thanks anyways!
– stephan
Answers
What you need is some kind of sentinel function, which is responsible to scan some folder from time to time and see whether some new file(s) arrived.
I did something like that in this very old forum thread:
http://forum.processing.org/one/topic/listing-last-10-modified-files-in-directory
But it's very complex and was meant to do more stuff than that. :-&
For maximum performance, best approach is having the folderSentinel() function running under another Thread. For that we'll use thread(""):
https://processing.org/reference/thread_.html
Another nice touch is to include a FilenameFilter:
http://docs.oracle.com/javase/8/docs/api/java/io/FilenameFilter.html
Then we can control for example which file types it's gonna be accepted by File's list() method:
http://docs.oracle.com/javase/8/docs/api/java/io/File.html#list-java.io.FilenameFilter-
All videos go into
List<Movie> videos
container.While new arrivals go into
List<Movie> newVids
temporarily.Every time folderSentinel() detects there are more File objects after a list() than there are Movie objects, it tries to find which 1(s) among the former are new.
For that it compares (via equals() inside a double
for ()
loop) each String from the former against each Movie's filename field from the latter.If at the end of the loop it doesn't get a match, a
new
Movie is instantiated using that String path. And it's temporarily add() into newVids.Once the double loop has completely finished, whatever newVids had collected goes into videos via addAll() method. And newVids gets clear().
And here's the whole example. Any doubts about it just ask here again: :D
wow! thank you! i would have never thought about an answer with the complete code needed for my case.
do you think it might be possible to show multiple videos at once? spreaded all over the canvas (randomly) with the same size? i would then need to clear them all at a specific time … and then go on with the next couple of movies.
http://forum.processing.org/two/discussion/8109/prepare-a-second-video-to-play-without-slowing-down-the-first-video
Awesome, how can I cycle through the videos within the folder?