Skip to content

Commit

Permalink
Expose VideoStreamPlayer video length
Browse files Browse the repository at this point in the history
  • Loading branch information
kinami-imai committed Jun 5, 2023
1 parent 543750a commit e3da917
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/classes/VideoStreamPlayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<tutorials>
</tutorials>
<methods>
<method name="get_stream_length" qualifiers="const">
<return type="float" />
<description>
The length of the current stream, in seconds.
[b]Note:[/b] For [VideoStreamTheora] streams (the built-in format supported by Godot), this value will always be zero, as getting the stream length is not implemented yet. The feature may be supported by video formats implemented by a GDExtension add-on.
</description>
</method>
<method name="get_stream_name" qualifiers="const">
<return type="String" />
<description>
Expand Down
8 changes: 8 additions & 0 deletions scene/gui/video_stream_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ String VideoStreamPlayer::get_stream_name() const {
return stream->get_name();
}

double VideoStreamPlayer::get_stream_length() const {
if (playback.is_null()) {
return 0;
}
return playback->get_length();
}

double VideoStreamPlayer::get_stream_position() const {
if (playback.is_null()) {
return 0;
Expand Down Expand Up @@ -468,6 +475,7 @@ void VideoStreamPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_audio_track"), &VideoStreamPlayer::get_audio_track);

ClassDB::bind_method(D_METHOD("get_stream_name"), &VideoStreamPlayer::get_stream_name);
ClassDB::bind_method(D_METHOD("get_stream_length"), &VideoStreamPlayer::get_stream_length);

ClassDB::bind_method(D_METHOD("set_stream_position", "position"), &VideoStreamPlayer::set_stream_position);
ClassDB::bind_method(D_METHOD("get_stream_position"), &VideoStreamPlayer::get_stream_position);
Expand Down
1 change: 1 addition & 0 deletions scene/gui/video_stream_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class VideoStreamPlayer : public Control {
float get_volume_db() const;

String get_stream_name() const;
double get_stream_length() const;
double get_stream_position() const;
void set_stream_position(double p_position);

Expand Down

0 comments on commit e3da917

Please sign in to comment.