VideoPlayer: Fix reloading translation remapped stream

Fixes #43917.

(cherry picked from commit 7d0c561e02)
This commit is contained in:
Rémi Verschelde 2024-01-23 20:20:18 +01:00 committed by Yuri Sizov
parent 2ff7b6c830
commit 98cfa8bcf2
3 changed files with 11 additions and 1 deletions

View File

@ -6,7 +6,6 @@
<description> <description>
A control used for playback of [VideoStream] resources. A control used for playback of [VideoStream] resources.
Supported video formats are [url=https://www.theora.org/]Ogg Theora[/url] ([code].ogv[/code], [VideoStreamTheora]) and any format exposed via a GDExtension plugin. Supported video formats are [url=https://www.theora.org/]Ogg Theora[/url] ([code].ogv[/code], [VideoStreamTheora]) and any format exposed via a GDExtension plugin.
[b]Note:[/b] Due to a bug, VideoStreamPlayer does not support localization remapping yet.
[b]Warning:[/b] On Web, video playback [i]will[/i] perform poorly due to missing architecture-specific assembly optimizations. [b]Warning:[/b] On Web, video playback [i]will[/i] perform poorly due to missing architecture-specific assembly optimizations.
</description> </description>
<tutorials> <tutorials>

View File

@ -224,6 +224,12 @@ bool VideoStreamPlayer::has_expand() const {
void VideoStreamPlayer::set_stream(const Ref<VideoStream> &p_stream) { void VideoStreamPlayer::set_stream(const Ref<VideoStream> &p_stream) {
stop(); stop();
// Make sure to handle stream changes seamlessly, e.g. when done via
// translation remapping.
if (stream.is_valid()) {
stream->disconnect("changed", callable_mp(this, &VideoStreamPlayer::set_stream));
}
AudioServer::get_singleton()->lock(); AudioServer::get_singleton()->lock();
mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
stream = p_stream; stream = p_stream;
@ -235,6 +241,10 @@ void VideoStreamPlayer::set_stream(const Ref<VideoStream> &p_stream) {
} }
AudioServer::get_singleton()->unlock(); AudioServer::get_singleton()->unlock();
if (stream.is_valid()) {
stream->connect("changed", callable_mp(this, &VideoStreamPlayer::set_stream).bind(stream));
}
if (!playback.is_null()) { if (!playback.is_null()) {
playback->set_paused(paused); playback->set_paused(paused);
texture = playback->get_texture(); texture = playback->get_texture();

View File

@ -172,6 +172,7 @@ Ref<VideoStreamPlayback> VideoStream::instantiate_playback() {
void VideoStream::set_file(const String &p_file) { void VideoStream::set_file(const String &p_file) {
file = p_file; file = p_file;
emit_changed();
} }
String VideoStream::get_file() { String VideoStream::get_file() {