Ren'Py Returning duration of clip before it is displayed[resolved]

Tribe

Member
Game Developer
May 5, 2021
226
492
I'm attempting to determine the length of video clips before they are displayed.

The catch is that I know nothing about the video.
The game will decide whether a clip will be shown for a few seconds or several minutes at a time.
What I'd like to see happen is:
Python:
random_display_time = renpy.random.randint( min_time, max_time )

if chosen_clip_duration > random_display_time:
    clip_start_pos = renpy.random.randint( 0.0, ( clip_duration - random_display_time ) )

So, if the clip will be shown for 30 seconds and is 60 seconds long, I'd like the start position to be anywhere between 0.0 and 30.0.

In its current state, my code requires the clip to be playing first in order to obtain the duration. To avoid crashes, I need to buffer it for at least a second.
Python:
call screen my_pause_screen(2)
timeout = renpy.music.get_duration(channel="random_clip") -2
The screen pauses on a separate layer, allowing the game to calculate the length of the clip. Pausing for 1 second also works, but the game rarely requires a fraction of a second longer and may cause the game to crash with a 0.0 timer error. It doesn't feel very elegant to me but it's holding up for now.

Does anyone have the goods? Thanks in advance!