diff --git a/doc/classes/VideoStreamPlayer.xml b/doc/classes/VideoStreamPlayer.xml
index 41f49a5a91a..2c149a9bbfa 100644
--- a/doc/classes/VideoStreamPlayer.xml
+++ b/doc/classes/VideoStreamPlayer.xml
@@ -61,6 +61,9 @@
If [code]true[/code], the video scales to the control size. Otherwise, the control minimum size will be automatically adjusted to match the video stream's dimensions.
+
+ If [code]true[/code], the video restarts when it reaches its end.
+
If [code]true[/code], the video is paused.
diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp
index 19a54e01c4c..07009ff9762 100644
--- a/scene/gui/video_stream_player.cpp
+++ b/scene/gui/video_stream_player.cpp
@@ -159,6 +159,10 @@ void VideoStreamPlayer::_notification(int p_notification) {
playback->update(delta); // playback->is_playing() returns false in the last video frame
if (!playback->is_playing()) {
+ if (loop) {
+ play();
+ return;
+ }
emit_signal(SceneStringNames::get_singleton()->finished);
}
} break;
@@ -221,6 +225,14 @@ bool VideoStreamPlayer::has_expand() const {
return expand;
}
+void VideoStreamPlayer::set_loop(bool p_loop) {
+ loop = p_loop;
+}
+
+bool VideoStreamPlayer::has_loop() const {
+ return loop;
+}
+
void VideoStreamPlayer::set_stream(const Ref &p_stream) {
stop();
@@ -461,6 +473,9 @@ void VideoStreamPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_paused", "paused"), &VideoStreamPlayer::set_paused);
ClassDB::bind_method(D_METHOD("is_paused"), &VideoStreamPlayer::is_paused);
+ ClassDB::bind_method(D_METHOD("set_loop", "loop"), &VideoStreamPlayer::set_loop);
+ ClassDB::bind_method(D_METHOD("has_loop"), &VideoStreamPlayer::has_loop);
+
ClassDB::bind_method(D_METHOD("set_volume", "volume"), &VideoStreamPlayer::set_volume);
ClassDB::bind_method(D_METHOD("get_volume"), &VideoStreamPlayer::get_volume);
@@ -498,6 +513,7 @@ void VideoStreamPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "has_autoplay");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_paused", "is_paused");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand"), "set_expand", "has_expand");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "has_loop");
ADD_PROPERTY(PropertyInfo(Variant::INT, "buffering_msec", PROPERTY_HINT_RANGE, "10,1000,suffix:ms"), "set_buffering_msec", "get_buffering_msec");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "stream_position", PROPERTY_HINT_RANGE, "0,1280000,0.1", PROPERTY_USAGE_NONE), "set_stream_position", "get_stream_position");
diff --git a/scene/gui/video_stream_player.h b/scene/gui/video_stream_player.h
index 1fd599a9e1f..14faab3ec17 100644
--- a/scene/gui/video_stream_player.h
+++ b/scene/gui/video_stream_player.h
@@ -65,6 +65,7 @@ class VideoStreamPlayer : public Control {
float volume = 1.0;
double last_audio_time = 0.0;
bool expand = false;
+ bool loop = false;
int buffering_ms = 500;
int audio_track = 0;
int bus_index = 0;
@@ -94,6 +95,9 @@ public:
void stop();
bool is_playing() const;
+ void set_loop(bool p_loop);
+ bool has_loop() const;
+
void set_paused(bool p_paused);
bool is_paused() const;