diff --git a/doc/classes/VideoStreamPlayer.xml b/doc/classes/VideoStreamPlayer.xml
index 46bc4f491d6..01bcca35907 100644
--- a/doc/classes/VideoStreamPlayer.xml
+++ b/doc/classes/VideoStreamPlayer.xml
@@ -73,6 +73,9 @@
If [code]true[/code], the video is paused.
+
+ The stream's current speed scale. [code]1.0[/code] is the normal speed, while [code]2.0[/code] is double speed and [code]0.5[/code] is half speed. A speed scale of [code]0.0[/code] pauses the video, similar to setting [member paused] to [code]true[/code].
+
The assigned video stream. See description for supported formats.
diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp
index 2249690c6c5..e4359817e3a 100644
--- a/scene/gui/video_stream_player.cpp
+++ b/scene/gui/video_stream_player.cpp
@@ -157,9 +157,9 @@ void VideoStreamPlayer::_notification(int p_notification) {
double delta = first_frame ? 0 : get_process_delta_time();
first_frame = false;
- resampler.set_playback_speed(Engine::get_singleton()->get_time_scale());
+ resampler.set_playback_speed(Engine::get_singleton()->get_time_scale() * speed_scale);
- playback->update(delta); // playback->is_playing() returns false in the last video frame
+ playback->update(delta * speed_scale); // playback->is_playing() returns false in the last video frame
if (!playback->is_playing()) {
resampler.flush();
@@ -433,6 +433,15 @@ float VideoStreamPlayer::get_volume_db() const {
}
}
+void VideoStreamPlayer::set_speed_scale(float p_speed_scale) {
+ ERR_FAIL_COND(p_speed_scale < 0.0);
+ speed_scale = p_speed_scale;
+}
+
+float VideoStreamPlayer::get_speed_scale() const {
+ return speed_scale;
+}
+
String VideoStreamPlayer::get_stream_name() const {
if (stream.is_null()) {
return "";
@@ -530,6 +539,9 @@ void VideoStreamPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_volume_db", "db"), &VideoStreamPlayer::set_volume_db);
ClassDB::bind_method(D_METHOD("get_volume_db"), &VideoStreamPlayer::get_volume_db);
+ ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &VideoStreamPlayer::set_speed_scale);
+ ClassDB::bind_method(D_METHOD("get_speed_scale"), &VideoStreamPlayer::get_speed_scale);
+
ClassDB::bind_method(D_METHOD("set_audio_track", "track"), &VideoStreamPlayer::set_audio_track);
ClassDB::bind_method(D_METHOD("get_audio_track"), &VideoStreamPlayer::get_audio_track);
@@ -559,6 +571,7 @@ void VideoStreamPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "VideoStream"), "set_stream", "get_stream");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01,suffix:dB"), "set_volume_db", "get_volume_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume", PROPERTY_HINT_RANGE, "0,15,0.01,exp", PROPERTY_USAGE_NONE), "set_volume", "get_volume");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale", PROPERTY_HINT_RANGE, "0,4,0.001,or_greater"), "set_speed_scale", "get_speed_scale");
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");
diff --git a/scene/gui/video_stream_player.h b/scene/gui/video_stream_player.h
index 0a80d8ca3bf..94c74481dc8 100644
--- a/scene/gui/video_stream_player.h
+++ b/scene/gui/video_stream_player.h
@@ -63,6 +63,7 @@ class VideoStreamPlayer : public Control {
bool paused_from_tree = false;
bool autoplay = false;
float volume = 1.0;
+ float speed_scale = 1.0;
bool expand = false;
bool loop = false;
bool first_frame = false;
@@ -107,6 +108,9 @@ public:
void set_volume_db(float p_db);
float get_volume_db() const;
+ void set_speed_scale(float p_speed_scale);
+ float get_speed_scale() const;
+
String get_stream_name() const;
double get_stream_length() const;
double get_stream_position() const;