Merge pull request #94268 from adamscott/fix-web-sample-playback-finished-signal-redux

Fix audio samples not being able to be "finished"
This commit is contained in:
Rémi Verschelde 2024-07-17 18:33:42 +02:00
commit 6d7ef2c33a
No known key found for this signature in database
GPG key ID: C3336907360768E1
5 changed files with 15 additions and 18 deletions

View file

@ -65,19 +65,7 @@ void AudioDriverWeb::_sample_playback_finished_callback(const char *p_playback_o
return;
}
Object *player_object = ObjectDB::get_instance(playback->player_id);
if (player_object == nullptr) {
return;
}
Node *player = Object::cast_to<Node>(player_object);
if (player == nullptr) {
return;
}
const StringName finished = SNAME("finished");
if (player->has_signal(finished)) {
player->emit_signal(finished);
}
AudioServer::get_singleton()->stop_sample_playback(playback);
}
void AudioDriverWeb::_audio_driver_process(int p_from, int p_samples) {

View file

@ -152,7 +152,6 @@ Ref<AudioStreamPlayback> AudioStreamPlayerInternal::play_basic() {
Ref<AudioSamplePlayback> sample_playback;
sample_playback.instantiate();
sample_playback->stream = stream;
sample_playback->player_id = node->get_instance_id();
stream_playback->set_sample_playback(sample_playback);
}
} else if (!stream->is_meta_stream()) {
@ -262,9 +261,6 @@ void AudioStreamPlayerInternal::seek(float p_seconds) {
void AudioStreamPlayerInternal::stop() {
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
AudioServer::get_singleton()->stop_playback_stream(playback);
if (_is_sample() && playback->get_sample_playback().is_valid()) {
AudioServer::get_singleton()->stop_sample_playback(playback->get_sample_playback());
}
}
stream_playbacks.clear();

View file

@ -49,7 +49,6 @@ class AudioSamplePlayback : public RefCounted {
public:
Ref<AudioStream> stream;
ObjectID player_id;
float offset = 0.0f;
Vector<AudioFrame> volume_vector;
StringName bus;

View file

@ -1220,6 +1220,12 @@ void AudioServer::start_playback_stream(Ref<AudioStreamPlayback> p_playback, con
void AudioServer::stop_playback_stream(Ref<AudioStreamPlayback> p_playback) {
ERR_FAIL_COND(p_playback.is_null());
// Handle sample playback.
if (p_playback->get_is_sample() && p_playback->get_sample_playback().is_valid()) {
AudioServer::get_singleton()->stop_sample_playback(p_playback->get_sample_playback());
return;
}
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
if (!playback_node) {
return;
@ -1358,6 +1364,10 @@ void AudioServer::set_playback_highshelf_params(Ref<AudioStreamPlayback> p_playb
bool AudioServer::is_playback_active(Ref<AudioStreamPlayback> p_playback) {
ERR_FAIL_COND_V(p_playback.is_null(), false);
if (p_playback->get_is_sample() && p_playback->get_sample_playback().is_valid()) {
return sample_playback_list.has(p_playback->get_sample_playback());
}
AudioStreamPlaybackListNode *playback_node = _find_playback_list_node(p_playback);
if (!playback_node) {
return false;
@ -1818,11 +1828,13 @@ void AudioServer::unregister_sample(const Ref<AudioSample> &p_sample) {
void AudioServer::start_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {
ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");
AudioDriver::get_singleton()->start_sample_playback(p_playback);
sample_playback_list.ordered_insert(p_playback);
}
void AudioServer::stop_sample_playback(const Ref<AudioSamplePlayback> &p_playback) {
ERR_FAIL_COND_MSG(p_playback.is_null(), "Parameter p_playback is null.");
AudioDriver::get_singleton()->stop_sample_playback(p_playback);
sample_playback_list.erase(p_playback);
}
void AudioServer::set_sample_playback_pause(const Ref<AudioSamplePlayback> &p_playback, bool p_paused) {

View file

@ -329,6 +329,8 @@ private:
friend class AudioDriver;
void _driver_process(int p_frames, int32_t *p_buffer);
LocalVector<Ref<AudioStreamPlayback>> sample_playback_list;
protected:
static void _bind_methods();