Skip to content

Commit 09f8b36

Browse files
authored
Reclaim busy players when they aren't playing (#25)
1 parent 5252ead commit 09f8b36

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

addons/sound_manager/abstract_audio_player_pool.gd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,20 @@ func mark_player_as_available(player: AudioStreamPlayer) -> void:
7575
if busy_players.has(player):
7676
busy_players.erase(player)
7777

78-
if not available_players.has(player):
78+
if available_players.size() >= default_pool_size:
79+
player.queue_free()
80+
elif not available_players.has(player):
7981
available_players.append(player)
8082

8183

8284
func increase_pool() -> void:
85+
# See if we can reclaim a rogue busy player
86+
for player in busy_players:
87+
if not player.playing:
88+
mark_player_as_available(player)
89+
return
90+
91+
# Otherwise, add a new player
8392
var player := AudioStreamPlayer.new()
8493
add_child(player)
8594
available_players.append(player)

examples/music.mp3

139 KB
Binary file not shown.

examples/music.mp3.import

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dest_files=["res://.godot/imported/music.mp3-8ca4afa70bdd800397f4305bc9ea3fe6.mp
1313
[params]
1414

1515
loop=true
16-
loop_offset=0
17-
bpm=0
18-
beat_count=0
16+
loop_offset=4.0
17+
bpm=120.0
18+
beat_count=16
1919
bar_beats=4

0 commit comments

Comments
 (0)