I created a moviefilein TOP connected to a null TOP which is connected to a container COMP. The moviefilein TOP is also connected to an audiomovie CHOP which is connected to an audiodevout CHOP. The moviefilein TOP is also connected to a info CHOP which is connected to a select CHOP, which is connected to a chopexecute DAT. The moviefilein TOP is also connected to a keyboardin CHOP which is connected to a select CHOP. When the key s is clicked, video 1 starts.
There is also second moviefilein TOP connected to a null TOP which is connected to a container COMP. The moviefilein TOP is also connected to an audiomovie CHOP which is connected to an audiodevout CHOP.
Both container COMPs are connected in a container COMP, which serves as main container.
In the chopexecute DAT, I wrote the following code:
def onValueChange(channel: Channel, sampleIndex: int, val: float,
prev: float):
"""
Called when a channel value changes.
Args:
channel: The Channel object which has changed
sampleIndex: The index of the changed sample
val: The numeric value of the changed sample
prev: The previous sample value
"""
maincomp = op('/project1/container3')
container1 = op('/project1/container1')
container2 = op('/project1/container2')
video1 = op('/project1/moviefilein1')
video2 = op('/project1/moviefilein2')
audio1 = op('/project1/audiomovie1')
audio2 = op('/project1/audiomovie2')
info = op('/project1/info1')
index = info['index'][0]
length = info['length'][0]
if length <= 0:
return
if index >= length - 1:
if maincomp.fetch('video1Finished', False):
return
maincomp.store('video1Finished', True)
video1.par.play = 0
audio1.par.play = 0
container1.par.opacity = 0
container2.par.opacity = 1
video2.par.cue.pulse()
video2.par.play = 1
audio2.par.play = 1
return
The code should execute that at the beginning the first video is displayed in the main container and after it has finished, it disappears and the second video appears and starts playing.
I’m aware you are asking about how to do it in python, but an option could be to use a simple switch TOP for the movie file and switch CHOP for the sound file, and switch back and forth with blending enabled.
To read the position of the video file, you could connect a logic CHOP after your info CHOP.
Thank you for your idea, @FaustoB I appreciate it.
I was also thinking about using a switch TOP and CHOP, but then I changed the structure a bit and was able to trigger the transition between the images with Python code where I connected to the first video a info CHOP which I connected to a select CHOP where the channels ‘index’ and ‘length’ were selected and then in a chopexecute DAT, I wrote a python code where an if statement together with the display and play parameters were used
in the file you posted, the CHOP Execute DAT is running on the onValueChange callback. With the Channel parameter of the CHOP Execute DAT being set to “*” the callback is being executed every time any of the referenced channels change their value - in your case this is not just the channels which particularly deal with the playback state of the movie, but also the callback executes when the cooktime or cook_frame channels (or any of the other channels) change.
If you want to go the Info CHOP route, a useful channel is the called “last_frame” which will go from 0 to 1 on the last frame of the movie that is playing. You can now use the CHOP Execute DAT’s onOffToOn callback to turn playing of on the respective Movie File In TOP and switch over the Containers.
You can still simplify your network by following @FaustoB advice and using a Switch TOP and Switch CHOP instead of duplicating the whole network.
thank you for your helpful message and hint with the channel “last_frame”. I had a similar approach where I used the channels ‘index’ and ‘length’ and included them into an if-statement: if the video’s current frame has reached the last frame (if info['index'][0] >= info['length'][0] - 1:), then make the first container invisible, stop the first video and its audio and display the second container and start playing the second video.
Your approach with using the channel ‘last_frame’ is also good. It makes the code shorter and simpler.
It’s interesting to see many different approaches for creating one functionality.