Add `stop_callable` to `AudioStreamPlayerInternal`
This commit is contained in:
parent
88f3b5f9d5
commit
8c7dd3cb61
|
@ -242,7 +242,7 @@ void AudioStreamPlayer2D::seek(float p_seconds) {
|
|||
|
||||
void AudioStreamPlayer2D::stop() {
|
||||
setplay.set(-1);
|
||||
internal->stop();
|
||||
internal->stop_basic();
|
||||
}
|
||||
|
||||
bool AudioStreamPlayer2D::is_playing() const {
|
||||
|
@ -430,7 +430,7 @@ void AudioStreamPlayer2D::_bind_methods() {
|
|||
}
|
||||
|
||||
AudioStreamPlayer2D::AudioStreamPlayer2D() {
|
||||
internal = memnew(AudioStreamPlayerInternal(this, callable_mp(this, &AudioStreamPlayer2D::play), true));
|
||||
internal = memnew(AudioStreamPlayerInternal(this, callable_mp(this, &AudioStreamPlayer2D::play), callable_mp(this, &AudioStreamPlayer2D::stop), true));
|
||||
cached_global_panning_strength = GLOBAL_GET("audio/general/2d_panning_strength");
|
||||
set_hide_clip_children(true);
|
||||
}
|
||||
|
|
|
@ -562,7 +562,7 @@ void AudioStreamPlayer3D::seek(float p_seconds) {
|
|||
|
||||
void AudioStreamPlayer3D::stop() {
|
||||
setplay.set(-1);
|
||||
internal->stop();
|
||||
internal->stop_basic();
|
||||
}
|
||||
|
||||
bool AudioStreamPlayer3D::is_playing() const {
|
||||
|
@ -862,7 +862,7 @@ void AudioStreamPlayer3D::_bind_methods() {
|
|||
}
|
||||
|
||||
AudioStreamPlayer3D::AudioStreamPlayer3D() {
|
||||
internal = memnew(AudioStreamPlayerInternal(this, callable_mp(this, &AudioStreamPlayer3D::play), true));
|
||||
internal = memnew(AudioStreamPlayerInternal(this, callable_mp(this, &AudioStreamPlayer3D::play), callable_mp(this, &AudioStreamPlayer3D::stop), true));
|
||||
velocity_tracker.instantiate();
|
||||
set_disable_scale(true);
|
||||
cached_global_panning_strength = GLOBAL_GET("audio/general/3d_panning_strength");
|
||||
|
|
|
@ -112,7 +112,7 @@ void AudioStreamPlayer::seek(float p_seconds) {
|
|||
}
|
||||
|
||||
void AudioStreamPlayer::stop() {
|
||||
internal->stop();
|
||||
internal->stop_basic();
|
||||
}
|
||||
|
||||
bool AudioStreamPlayer::is_playing() const {
|
||||
|
@ -283,7 +283,7 @@ void AudioStreamPlayer::_bind_methods() {
|
|||
}
|
||||
|
||||
AudioStreamPlayer::AudioStreamPlayer() {
|
||||
internal = memnew(AudioStreamPlayerInternal(this, callable_mp(this, &AudioStreamPlayer::play), false));
|
||||
internal = memnew(AudioStreamPlayerInternal(this, callable_mp(this, &AudioStreamPlayer::play), callable_mp(this, &AudioStreamPlayer::stop), false));
|
||||
}
|
||||
|
||||
AudioStreamPlayer::~AudioStreamPlayer() {
|
||||
|
|
|
@ -132,7 +132,7 @@ Ref<AudioStreamPlayback> AudioStreamPlayerInternal::play_basic() {
|
|||
}
|
||||
ERR_FAIL_COND_V_MSG(!node->is_inside_tree(), stream_playback, "Playback can only happen when a node is inside the scene tree");
|
||||
if (stream->is_monophonic() && is_playing()) {
|
||||
stop();
|
||||
stop_callable.call();
|
||||
}
|
||||
stream_playback = stream->instantiate_playback();
|
||||
ERR_FAIL_COND_V_MSG(stream_playback.is_null(), stream_playback, "Failed to instantiate playback.");
|
||||
|
@ -242,7 +242,7 @@ void AudioStreamPlayerInternal::set_stream(Ref<AudioStream> p_stream) {
|
|||
if (stream.is_valid()) {
|
||||
stream->disconnect(SNAME("parameter_list_changed"), callable_mp(this, &AudioStreamPlayerInternal::_update_stream_parameters));
|
||||
}
|
||||
stop();
|
||||
stop_callable.call();
|
||||
stream = p_stream;
|
||||
_update_stream_parameters();
|
||||
if (stream.is_valid()) {
|
||||
|
@ -253,12 +253,12 @@ void AudioStreamPlayerInternal::set_stream(Ref<AudioStream> p_stream) {
|
|||
|
||||
void AudioStreamPlayerInternal::seek(float p_seconds) {
|
||||
if (is_playing()) {
|
||||
stop();
|
||||
stop_callable.call();
|
||||
play_callable.call(p_seconds);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioStreamPlayerInternal::stop() {
|
||||
void AudioStreamPlayerInternal::stop_basic() {
|
||||
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
|
||||
AudioServer::get_singleton()->stop_playback_stream(playback);
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ void AudioStreamPlayerInternal::set_playing(bool p_enable) {
|
|||
if (p_enable) {
|
||||
play_callable.call(0.0);
|
||||
} else {
|
||||
stop();
|
||||
stop_callable.call();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,9 +339,10 @@ StringName AudioStreamPlayerInternal::get_bus() const {
|
|||
return SceneStringName(Master);
|
||||
}
|
||||
|
||||
AudioStreamPlayerInternal::AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, bool p_physical) {
|
||||
AudioStreamPlayerInternal::AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, const Callable &p_stop_callable, bool p_physical) {
|
||||
node = p_node;
|
||||
play_callable = p_play_callable;
|
||||
stop_callable = p_stop_callable;
|
||||
physical = p_physical;
|
||||
bus = SceneStringName(Master);
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ private:
|
|||
|
||||
Node *node = nullptr;
|
||||
Callable play_callable;
|
||||
Callable stop_callable;
|
||||
bool physical = false;
|
||||
AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;
|
||||
|
||||
|
@ -94,7 +95,7 @@ public:
|
|||
|
||||
Ref<AudioStreamPlayback> play_basic();
|
||||
void seek(float p_seconds);
|
||||
void stop();
|
||||
void stop_basic();
|
||||
bool is_playing() const;
|
||||
float get_playback_position();
|
||||
|
||||
|
@ -110,7 +111,7 @@ public:
|
|||
void set_playback_type(AudioServer::PlaybackType p_playback_type);
|
||||
AudioServer::PlaybackType get_playback_type() const;
|
||||
|
||||
AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, bool p_physical);
|
||||
AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, const Callable &p_stop_callable, bool p_physical);
|
||||
};
|
||||
|
||||
#endif // AUDIO_STREAM_PLAYER_INTERNAL_H
|
||||
|
|
Loading…
Reference in New Issue