diff options
Diffstat (limited to 'scene/audio')
-rw-r--r-- | scene/audio/audio_stream_player.cpp | 13 | ||||
-rw-r--r-- | scene/audio/audio_stream_player.h | 1 |
2 files changed, 9 insertions, 5 deletions
diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp index 42f76068e7..6c37d6f81d 100644 --- a/scene/audio/audio_stream_player.cpp +++ b/scene/audio/audio_stream_player.cpp @@ -111,7 +111,7 @@ float AudioStreamPlayer::get_volume_db() const { } void AudioStreamPlayer::set_pitch_scale(float p_pitch_scale) { - ERR_FAIL_COND(p_pitch_scale <= 0.0); + ERR_FAIL_COND(!(p_pitch_scale > 0.0)); pitch_scale = p_pitch_scale; for (Ref<AudioStreamPlayback> &playback : stream_playbacks) { @@ -307,11 +307,13 @@ void AudioStreamPlayer::_bus_layout_changed() { notify_property_list_changed(); } +bool AudioStreamPlayer::has_stream_playback() { + return !stream_playbacks.is_empty(); +} + Ref<AudioStreamPlayback> AudioStreamPlayer::get_stream_playback() { - if (!stream_playbacks.is_empty()) { - return stream_playbacks[stream_playbacks.size() - 1]; - } - return nullptr; + ERR_FAIL_COND_V_MSG(stream_playbacks.is_empty(), Ref<AudioStreamPlayback>(), "Player is inactive. Call play() before requesting get_stream_playback()."); + return stream_playbacks[stream_playbacks.size() - 1]; } void AudioStreamPlayer::_bind_methods() { @@ -349,6 +351,7 @@ void AudioStreamPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_max_polyphony", "max_polyphony"), &AudioStreamPlayer::set_max_polyphony); ClassDB::bind_method(D_METHOD("get_max_polyphony"), &AudioStreamPlayer::get_max_polyphony); + ClassDB::bind_method(D_METHOD("has_stream_playback"), &AudioStreamPlayer::has_stream_playback); ClassDB::bind_method(D_METHOD("get_stream_playback"), &AudioStreamPlayer::get_stream_playback); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream"); diff --git a/scene/audio/audio_stream_player.h b/scene/audio/audio_stream_player.h index 5368391073..d1f6fca2ee 100644 --- a/scene/audio/audio_stream_player.h +++ b/scene/audio/audio_stream_player.h @@ -107,6 +107,7 @@ public: void set_stream_paused(bool p_pause); bool get_stream_paused() const; + bool has_stream_playback(); Ref<AudioStreamPlayback> get_stream_playback(); AudioStreamPlayer(); |