summaryrefslogtreecommitdiff
path: root/scene/audio
diff options
context:
space:
mode:
Diffstat (limited to 'scene/audio')
-rw-r--r--scene/audio/audio_player.cpp19
-rw-r--r--scene/audio/audio_player.h2
2 files changed, 18 insertions, 3 deletions
diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp
index a8ddcbbb45..5d71f702df 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) */
@@ -29,6 +29,8 @@
/*************************************************************************/
#include "audio_player.h"
+#include "engine.h"
+
void AudioStreamPlayer::_mix_audio() {
if (!stream_playback.is_valid()) {
@@ -100,11 +102,20 @@ void AudioStreamPlayer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
AudioServer::get_singleton()->add_callback(_mix_audios, this);
- if (autoplay && !get_tree()->is_editor_hint()) {
+ if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
}
+ 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);
@@ -156,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);
}
}
@@ -170,6 +182,7 @@ void AudioStreamPlayer::stop() {
if (stream_playback.is_valid()) {
active = false;
+ set_process_internal(false);
}
}
@@ -295,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() {
diff --git a/scene/audio/audio_player.h b/scene/audio/audio_player.h
index 8bd6844dec..4bfa84f766 100644
--- a/scene/audio/audio_player.h
+++ b/scene/audio/audio_player.h
@@ -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) */