How to start a VideoPlayer stream at a certain position?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Remedee

I have a scene playing a video. I would like to change the scene and continue that video on the new scene from where it left off. I’m passing the stream_position of the video through a global variable.

However, when I use videoPlayerNode.set_stream_position(global.stream_position) then play the video, it still starts from the beginning despite global.stream_position being > 0. I have attempted setting the stream position after playing the video, but that does not work either.

What is the proper way to start a video at a certain position?

As of writing this, it’s not implemented apart from GDNative videos. See https://docs.godotengine.org/en/stable/classes/class_videoplayer.html#class-videoplayer-property-stream-position

SteveSmith | 2022-09-26 09:12

:bust_in_silhouette: Reply From: Zylann

If setting stream position from a valid position doesn’t work, it sounds like a bug with the node. Or maybe there is an order between the time you play and the time you seek? If it doesn’t work either it could be reported on the issue tracker.

Instead of saving the stream position, a workaround would be to not destroy the video player when you change scenes, keep the whole node around in a branch of the tree that doesn’t get wiped out (like an autoload) or tweak your game so that it doesn’t need to use change_scene, instead change only a child branch (because change_scene is only a shortcut to replace the first child of the scene tree root with another instance).

root
- CurrentLevel <-- if this is swapped it will wipe VideoPlayer
	- VideoPlayer
	- Other stuff

root
- VideoPlayer
- CurrentLevel <-- this can be swapped without wiping VideoPlayer
	- Other stuff

I was able to make it work by playing the video in an AutoLoad. Then I can just remove it as a child from the first scene, and add it as a child of the new scene and it will still be playing at the same point. Thanks!

Remedee | 2019-09-17 18:05