Ren'Py Video Partial Playback

Tribe

Member
Game Developer
May 5, 2021
224
482
I'm trying to apply partial playback to randomly displayed videos
I've gotten it to work to some extent after referring to the , but I've run into an issue at every turn along the way.
As always, we can't define the video first because we don't know anything about the movie in question, only that it's probably compatible with Ren'Py...

video_clip = "videos/the_move.webm"

My usual method for displaying a video:
Python:
init python:
    renpy.music.register_channel("animation", mixer="voice", loop=False, stop_on_mute=False, tight=False, movie=True)
    setattr(store, video_clip, Movie(size=(1280,720), play="{}".format("Videos/the_movie.webm"), channel="animation"))

label start:
    show expression getattr(store, video_clip) as tmpmovie
I couldn't find a way to apply <from to> to my usual method so I have to venture out of my comfort zone.

Play movie:
Code:
label start:
    play movie "<from 5.0 to 10.0>videos/the_move.webm"
So majestic and simple. Almost too easy. Almost.
This plays the sound through the music mixer. Unless I want to rewrite all of my code, I need to make this play through the voice mixer.
Easy fix...

Create a channel using a different mixer:
Python:
init python:
    renpy.music.register_channel("new_channel", mixer="voice", loop=False, stop_on_mute=False, tight=False, movie=True)

label start:
    play new_channel "<from 5.0 to 10.0>videos/the_move.webm"
Sounds great... but now there's no video.
Only sound.

I was originally going to show all of the combinations of show/play, channels, and Movie() combinations but it doesn't seem as funny anymore.
Someone please give me the juice for this one. I feel like an infant trying to mash the square piece in the circle hole.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,299
15,167
Sounds great... but now there's no video.
Only sound.
What is normal. By default, only one channel care about the video, the "movie" channel. But this don't mean that there's no solution. You just need to define your own channel for the movies with , and ask Ren'Py to use it through .

Python:
init python:
    #  Create your own channel, that will use the /voice/ mixer, and specify that it will be used to
    # play movie, not just music.
    renpy.music.register_channel( "movieOverVoice", "voice", movie=True )
    #  Then, tell Ren'Py to automatically use that channel when it display a movie.
    config.single_movie_channel = "movieOverVoice"
 
  • Star-struck
Reactions: Tribe

Tribe

Member
Game Developer
May 5, 2021
224
482
What is normal. By default, only one channel care about the video, the "movie" channel. But this don't mean that there's no solution. You just need to define your own channel for the movies with , and ask Ren'Py to use it through .

Python:
init python:
    #  Create your own channel, that will use the /voice/ mixer, and specify that it will be used to
    # play movie, not just music.
    renpy.music.register_channel( "movieOverVoice", "voice", movie=True )
    #  Then, tell Ren'Py to automatically use that channel when it display a movie.
    config.single_movie_channel = "movieOverVoice"
Hmm.
I did it and the result is exactly the same.
Even the movie channel functions the same after using config.single_movie_channel = "movieOverVoice"
 

Tribe

Member
Game Developer
May 5, 2021
224
482
What is normal. By default, only one channel care about the video, the "movie" channel. But this don't mean that there's no solution. You just need to define your own channel for the movies with , and ask Ren'Py to use it through .

Python:
init python:
    #  Create your own channel, that will use the /voice/ mixer, and specify that it will be used to
    # play movie, not just music.
    renpy.music.register_channel( "movieOverVoice", "voice", movie=True )
    #  Then, tell Ren'Py to automatically use that channel when it display a movie.
    config.single_movie_channel = "movieOverVoice"
I'm about to be late for an appointment but I think it's working like this:
Python:
init python:
    renpy.music.register_channel("animation", mixer="voice", movie=True)

label start:
    $ video_clip = "Videos/the_movie.wepm"
    $ the_clip = Movie(size=(1280,720), play="<from 5.0 to 10.0>{}".format(video_clip), channel="animation", loop=False)
    show expression the_clip
Can't test it much further, gtg. Love ya bbl
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,299
15,167
Even the movie channel functions the same after using config.single_movie_channel = "movieOverVoice"
That the movie channel don't change, it's normal, but that you can't use that the sound do not play in the voice channel is strange. It works as expected the 7.5.3, and there's no reason for it to not works with the 8.0.3 nor with later version :/


I'm about to be late for an appointment but I think it's working like this:
$ the_clip = Movie(size=(1280,720), play="<from 5.0 to 10.0>{}".format(video_clip), channel="animation", loop=False)
show expression the_clip[/CODE]

Can't test it much further, gtg. Love ya bbl
The channel property do not works with the 7.5.3, reason why I fell back on the configuration value. Strange :/

I can't test right now, but I'll look with the 8.1.x version once back at home.
 
  • Like
Reactions: Tribe

Tribe

Member
Game Developer
May 5, 2021
224
482
Thanks to finally finding a solution to getting the clip's duration before it is played, I think I've found the solution to getting the partial playback to work as I intended. It still feels a little sketchy, but it's working...

Depending on whether the player-defined settings for how long the clip will be displayed exceed the length of the clip, the clip will either loop or play a portion of the clip.
Python:
python:
    video_clip = renpy.random.choice(video_list)
    clip_duration = Duraction_Of_Clip(video_clip) # function that returns length of clip using a module
    show_time = renpy.random.randint(minimum_seconds_for_videos, maximum_seconds_for_videos)
    partial_playback = False
    if show_time < clip_duration:
        partial_playback = True
        start_from = renpy.random.randint(0, (clip_duration - show_time))
        play_to = start_from + show_time
        setattr(store, "partial_video_clip", Movie(size=(1280,720), play="<from {} to {}>{}".format(start_from, play_to, video_clip), channel="animation"))

Then the clip will either loop or be played from a random start point depending on the display time settings:
Python:
label start:
    if partial_playback:
        show expression getattr(store, "partial_video_clip") as tmpmovie at truecenter
    else:
        show expression getattr(store, video_clip) as tmpmovie at truecenter