From e3da9176a0b51459126469718fa19502655a3493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E4=BA=95=E3=81=8D=E3=81=AA=E3=81=BF?= Date: Mon, 5 Jun 2023 00:59:23 +0200 Subject: [PATCH] Expose VideoStreamPlayer video length --- doc/classes/VideoStreamPlayer.xml | 7 +++++++ scene/gui/video_stream_player.cpp | 8 ++++++++ scene/gui/video_stream_player.h | 1 + 3 files changed, 16 insertions(+) diff --git a/doc/classes/VideoStreamPlayer.xml b/doc/classes/VideoStreamPlayer.xml index 6ba2e425577..746e26008f7 100644 --- a/doc/classes/VideoStreamPlayer.xml +++ b/doc/classes/VideoStreamPlayer.xml @@ -12,6 +12,13 @@ + + + + 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. + + diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp index 1f3bbff779e..35ebe2dc206 100644 --- a/scene/gui/video_stream_player.cpp +++ b/scene/gui/video_stream_player.cpp @@ -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; @@ -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); diff --git a/scene/gui/video_stream_player.h b/scene/gui/video_stream_player.h index 1fd599a9e1f..642562fc5ea 100644 --- a/scene/gui/video_stream_player.h +++ b/scene/gui/video_stream_player.h @@ -104,6 +104,7 @@ public: 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);