diff options
Diffstat (limited to 'scene/audio/audio_player.cpp')
-rw-r--r-- | scene/audio/audio_player.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp index d4d8f7dbed..8bd924e7ce 100644 --- a/scene/audio/audio_player.cpp +++ b/scene/audio/audio_player.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -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); @@ -130,12 +139,12 @@ void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) { stream = p_stream; stream_playback = p_stream->instance_playback(); + AudioServer::get_singleton()->unlock(); + if (stream_playback.is_null()) { stream.unref(); ERR_FAIL_COND(stream_playback.is_null()); } - - AudioServer::get_singleton()->unlock(); } Ref<AudioStream> AudioStreamPlayer::get_stream() const { @@ -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() { |