added finished signals to audio stream players, fixes #9928

This commit is contained in:
Juan Linietsky 2017-08-25 11:58:21 -03:00
parent 3061eca190
commit a1c03a69d2
3 changed files with 20 additions and 0 deletions

View file

@ -224,6 +224,7 @@ void AudioStreamPlayer2D::_notification(int p_what) {
if (!active) {
set_fixed_process_internal(false);
_change_notify("playing"); //update property in editor
emit_signal("finished");
}
}
}
@ -442,6 +443,9 @@ void AudioStreamPlayer2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "attenuation", PROPERTY_HINT_EXP_EASING), "set_attenuation", "get_attenuation");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
ADD_PROPERTY(PropertyInfo(Variant::INT, "area_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_area_mask", "get_area_mask");
ADD_SIGNAL(MethodInfo("finished"));
}
AudioStreamPlayer2D::AudioStreamPlayer2D() {

View file

@ -533,6 +533,7 @@ void AudioStreamPlayer3D::_notification(int p_what) {
if (!active) {
set_fixed_process_internal(false);
_change_notify("playing"); //update property in editor
emit_signal("finished");
}
}
}
@ -898,6 +899,8 @@ void AudioStreamPlayer3D::_bind_methods() {
BIND_ENUM_CONSTANT(DOPPLER_TRACKING_DISABLED);
BIND_ENUM_CONSTANT(DOPPLER_TRACKING_IDLE_STEP);
BIND_ENUM_CONSTANT(DOPPLER_TRACKING_FIXED_STEP);
ADD_SIGNAL(MethodInfo("finished"));
}
AudioStreamPlayer3D::AudioStreamPlayer3D() {

View file

@ -107,6 +107,15 @@ void AudioStreamPlayer::_notification(int p_what) {
}
}
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (!active || (setseek < 0 && !stream_playback->is_playing())) {
active = false;
emit_signal("finished");
set_process_internal(false);
}
}
if (p_what == NOTIFICATION_EXIT_TREE) {
AudioServer::get_singleton()->remove_callback(_mix_audios, this);
@ -158,6 +167,7 @@ void AudioStreamPlayer::play(float p_from_pos) {
mix_volume_db = volume_db; //reset volume ramp
setseek = p_from_pos;
active = true;
set_process_internal(true);
}
}
@ -172,6 +182,7 @@ void AudioStreamPlayer::stop() {
if (stream_playback.is_valid()) {
active = false;
set_process_internal(false);
}
}
@ -297,6 +308,8 @@ void AudioStreamPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mix_target", PROPERTY_HINT_ENUM, "Stereo,Surround,Center"), "set_mix_target", "get_mix_target");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus");
ADD_SIGNAL(MethodInfo("finished"));
}
AudioStreamPlayer::AudioStreamPlayer() {