Cannot get a video to loop correctly :(

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

Hey guys! Converting my… 30k LOC HTML 5 Game over to Godot.

Working on my intro screen right now, looks like Godot only likes Ogg Vorbis video files which is fine.

Having an issue here

Basically, was looking over the methods for VideoPlayer and cannot find anything that would set the video to loop. I tried Autoplay, which works, but was just curious if this is something the Godot team might support or do we need to build our own function?

King Regards,

Hey guys, I got something going:


extends VideoPlayer
func _process(delta):
	var isPlaying = is_playing()
	if isPlaying == false:
		play()
		
	pass
	
func _ready():
	# Called every time the node is added to the scene.
	# Initialization here
	set_process(true)
	
	
	set_autoplay(true)
	print('Autoplay set to true')
	
	print(has_autoplay())
	pass

Problem is, there is a slight delay (1-2 seconds) when the video re-starts and it’s not seamless. Hmm… Any idea?

wombatTurkey | 2016-03-06 08:32

:bust_in_silhouette: Reply From: Daniel Lewan

Check if this help (script attached to parent of VideoPlayer).

var video_player
var video

func _ready():
	video_player = get_node("Panel/VideoPlayer")
	video = preload("res://video.ogv")
	video_player.set_stream( video )
	set_process( true )
	
func _process(delta):
	if not video_player.is_playing():
	video_player.play()

Edit: WTF Is wrong with markdown here? Code blocks ``` don’t want to work

You mean, GitHub Flavoured Markdown :wink:

Bojidar Marinov | 2016-03-11 20:33

No, every Markdown I’ve been using. Gihub’s one have some nice features but I think backticks are “standard” http://commonmark.org/

Daniel Lewan | 2016-03-12 01:10

:bust_in_silhouette: Reply From: pakchano

To get exactly what you need, following your code posted:

extends VideoPlayer        

func _ready(): #{        	
    set_process(true)
#}

func _process(delta): #{
    if not is_playing():
        play()
#}

I’m a bit late… hope this helps someone else.

:bust_in_silhouette: Reply From: ichster

Attach this to VideoPlayer node:

extends VideoPlayer

func _ready():
	self.connect("finished", self, "_on_Finished")
	self.set_process(false)
	self.set_physics_process(false)

func _on_Finished():
	play()

Thank you! This script works great for my project.

Sam Feng | 2020-12-11 04:52

Thank you so much, this was just what I was looking for.

cybereality | 2021-04-25 16:21