Skip to content

Commit

Permalink
Add loop property to VideoStreamPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
kinami-imai committed Jun 5, 2023
1 parent 543750a commit 15719e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/classes/VideoStreamPlayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<member name="expand" type="bool" setter="set_expand" getter="has_expand" default="false">
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.
</member>
<member name="loop" type="bool" setter="set_loop" getter="has_loop" default="false">
If [code]true[/code], the video restarts when it reaches its end.
</member>
<member name="paused" type="bool" setter="set_paused" getter="is_paused" default="false">
If [code]true[/code], the video is paused.
</member>
Expand Down
16 changes: 16 additions & 0 deletions scene/gui/video_stream_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<VideoStream> &p_stream) {
stop();

Expand Down Expand Up @@ -458,6 +470,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);

Expand Down Expand Up @@ -495,6 +510,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");

Expand Down
4 changes: 4 additions & 0 deletions scene/gui/video_stream_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,6 +95,9 @@ class VideoStreamPlayer : public Control {
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;

Expand Down

0 comments on commit 15719e2

Please sign in to comment.