mirror of
https://github.com/izzy2lost/shinobu.git
synced 2026-03-26 16:50:24 -07:00
Bring back video player process_while_paused
This commit is contained in:
@@ -142,7 +142,7 @@ void VideoStreamPlayer::_notification(int p_notification) {
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
|
||||
|
||||
if (stream.is_null() || paused || playback.is_null() || !playback->is_playing()) {
|
||||
if (stream.is_null() || (paused && !process_while_paused) || playback.is_null() || !playback->is_playing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -151,11 +151,10 @@ void VideoStreamPlayer::_notification(int p_notification) {
|
||||
double delta = last_audio_time == 0 ? 0 : audio_time - last_audio_time;
|
||||
last_audio_time = audio_time;
|
||||
|
||||
if (delta == 0) {
|
||||
return;
|
||||
if (paused) {
|
||||
delta = 0.0f;
|
||||
}
|
||||
|
||||
playback->update(delta); // playback->is_playing() returns false in the last video frame
|
||||
playback->update(delta * playback_speed); // playback->is_playing() returns false in the last video frame
|
||||
|
||||
if (!playback->is_playing()) {
|
||||
if (loop) {
|
||||
@@ -181,7 +180,7 @@ void VideoStreamPlayer::_notification(int p_notification) {
|
||||
case NOTIFICATION_PAUSED: {
|
||||
if (is_playing() && !is_paused()) {
|
||||
paused_from_tree = true;
|
||||
if (playback.is_valid()) {
|
||||
if (playback.is_valid() && !process_while_paused) {
|
||||
playback->set_paused(true);
|
||||
set_process_internal(false);
|
||||
}
|
||||
@@ -257,7 +256,7 @@ void VideoStreamPlayer::set_stream(const Ref<VideoStream> &p_stream) {
|
||||
}
|
||||
|
||||
if (!playback.is_null()) {
|
||||
playback->set_paused(paused);
|
||||
playback->set_paused(paused && !process_while_paused);
|
||||
texture = playback->get_texture();
|
||||
|
||||
const int channels = playback->get_channels();
|
||||
@@ -280,7 +279,6 @@ void VideoStreamPlayer::set_stream(const Ref<VideoStream> &p_stream) {
|
||||
resampler.clear();
|
||||
AudioServer::get_singleton()->unlock();
|
||||
}
|
||||
|
||||
queue_redraw();
|
||||
|
||||
if (!expand) {
|
||||
@@ -346,7 +344,7 @@ void VideoStreamPlayer::set_paused(bool p_paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playback.is_valid()) {
|
||||
if (playback.is_valid() && !process_while_paused) {
|
||||
playback->set_paused(p_paused);
|
||||
set_process_internal(!p_paused);
|
||||
}
|
||||
@@ -462,6 +460,22 @@ StringName VideoStreamPlayer::get_bus() const {
|
||||
return SceneStringName(Master);
|
||||
}
|
||||
|
||||
float VideoStreamPlayer::get_playback_speed() const {
|
||||
return playback_speed;
|
||||
}
|
||||
|
||||
void VideoStreamPlayer::set_playback_speed(float p_playback_speed) {
|
||||
playback_speed = p_playback_speed;
|
||||
}
|
||||
|
||||
void VideoStreamPlayer::set_process_while_paused(bool p_process_while_paused) {
|
||||
process_while_paused = p_process_while_paused;
|
||||
}
|
||||
|
||||
bool VideoStreamPlayer::get_process_while_paused() const {
|
||||
return process_while_paused;
|
||||
}
|
||||
|
||||
void VideoStreamPlayer::_validate_property(PropertyInfo &p_property) const {
|
||||
if (p_property.name == "bus") {
|
||||
String options;
|
||||
@@ -519,6 +533,12 @@ void VideoStreamPlayer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_bus", "bus"), &VideoStreamPlayer::set_bus);
|
||||
ClassDB::bind_method(D_METHOD("get_bus"), &VideoStreamPlayer::get_bus);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_playback_speed", "playback_speed"), &VideoStreamPlayer::set_playback_speed);
|
||||
ClassDB::bind_method(D_METHOD("get_playback_speed"), &VideoStreamPlayer::get_playback_speed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_process_while_paused", "process_while_paused"), &VideoStreamPlayer::set_process_while_paused);
|
||||
ClassDB::bind_method(D_METHOD("get_process_while_paused"), &VideoStreamPlayer::get_process_while_paused);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_video_texture"), &VideoStreamPlayer::get_video_texture);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("finished"));
|
||||
@@ -533,6 +553,8 @@ void VideoStreamPlayer::_bind_methods() {
|
||||
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");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "playback_speed", PROPERTY_HINT_RANGE, "0,2,0.1"), "set_playback_speed", "get_playback_speed");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "process_while_paused"), "set_process_while_paused", "get_process_while_paused");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ class VideoStreamPlayer : public Control {
|
||||
int buffering_ms = 500;
|
||||
int audio_track = 0;
|
||||
int bus_index = 0;
|
||||
float playback_speed = 1.0f;
|
||||
bool process_while_paused = false;
|
||||
|
||||
StringName bus;
|
||||
|
||||
@@ -124,6 +126,12 @@ public:
|
||||
void set_bus(const StringName &p_bus);
|
||||
StringName get_bus() const;
|
||||
|
||||
float get_playback_speed() const;
|
||||
void set_playback_speed(float p_playback_speed);
|
||||
|
||||
void set_process_while_paused(bool p_process_while_paused);
|
||||
bool get_process_while_paused() const;
|
||||
|
||||
VideoStreamPlayer();
|
||||
~VideoStreamPlayer();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user