|
1 | 1 | package funkin.audio; |
2 | 2 |
|
3 | | -import lime.media.AudioSource; |
4 | 3 | import flixel.group.FlxGroup.FlxTypedGroup; |
| 4 | +import flixel.sound.FlxSound; |
5 | 5 | import flixel.tweens.FlxTween; |
6 | 6 |
|
7 | 7 | /** |
8 | 8 | * A group of FunkinSounds that are all synced together. |
9 | 9 | * Unlike FlxSoundGroup, you can also control their time and pitch. |
10 | 10 | */ |
11 | | -@:access(flixel.sound.FlxSound) |
12 | 11 | @:access(funkin.audio.FunkinSound) |
13 | 12 | @:nullSafety |
14 | 13 | class SoundGroup extends FlxTypedGroup<FunkinSound> |
@@ -106,71 +105,47 @@ class SoundGroup extends FlxTypedGroup<FunkinSound> |
106 | 105 | */ |
107 | 106 | public function pause() |
108 | 107 | { |
109 | | - forEachAlive(function(sound:FunkinSound) { |
110 | | - sound.pause(); |
111 | | - }); |
| 108 | + if (members != null) FlxSound.pauseSounds(cast members); |
112 | 109 | } |
113 | 110 |
|
114 | 111 | /** |
115 | 112 | * Play all the sounds in the group. |
116 | 113 | */ |
117 | 114 | public function play(forceRestart:Bool = false, startTime:Float = 0.0, ?endTime:Float) |
118 | 115 | { |
119 | | - var sources:Array<AudioSource> = []; |
| 116 | + var sounds:Array<FlxSound> = []; |
120 | 117 |
|
121 | 118 | forEachAlive(function(sound:FunkinSound) { |
122 | 119 | if (sound.playing && !forceRestart || sound.length < startTime) |
123 | 120 | { |
124 | 121 | return; |
125 | 122 | } |
126 | 123 |
|
127 | | - if (sound._pausedByHandler) |
128 | | - { |
129 | | - sound.play(true, startTime, endTime); |
130 | | - } |
131 | | - else |
132 | | - { |
133 | | - sound.prepare(startTime, endTime); |
134 | | - sources.push(sound.source); |
135 | | - |
136 | | - sound._paused = false; |
137 | | - sound._completed = false; |
138 | | - sound.active = true; |
139 | | - } |
| 124 | + sound.prepare(startTime, endTime); |
| 125 | + sounds.push(sound); |
140 | 126 | }); |
141 | 127 |
|
142 | | - AudioSource.playSources(sources); |
| 128 | + FlxSound.playSounds(sounds); |
143 | 129 | } |
144 | 130 |
|
145 | 131 | /** |
146 | 132 | * Resume all the sounds in the group. |
147 | 133 | */ |
148 | 134 | public function resume() |
149 | 135 | { |
150 | | - var sources:Array<AudioSource> = []; |
| 136 | + var sounds:Array<FlxSound> = []; |
151 | 137 |
|
152 | 138 | forEachAlive(function(sound:FunkinSound) { |
153 | 139 | if (sound.playing || !sound._paused) |
154 | 140 | { |
155 | 141 | return; |
156 | 142 | } |
157 | 143 |
|
158 | | - if (sound._pausedByHandler) |
159 | | - { |
160 | | - sound.resume(); |
161 | | - } |
162 | | - else |
163 | | - { |
164 | | - sound.prepare(sound.time); |
165 | | - sources.push(sound.source); |
166 | | - |
167 | | - sound._paused = false; |
168 | | - sound._completed = false; |
169 | | - sound.active = true; |
170 | | - } |
| 144 | + sound.prepare(sound.time); |
| 145 | + sounds.push(sound); |
171 | 146 | }); |
172 | 147 |
|
173 | | - AudioSource.playSources(sources); |
| 148 | + FlxSound.playSounds(sounds); |
174 | 149 | } |
175 | 150 |
|
176 | 151 | /** |
@@ -200,12 +175,7 @@ class SoundGroup extends FlxTypedGroup<FunkinSound> |
200 | 175 | */ |
201 | 176 | public function stop():Void |
202 | 177 | { |
203 | | - if (members != null) |
204 | | - { |
205 | | - forEachAlive(function(sound:FunkinSound) { |
206 | | - sound.stop(); |
207 | | - }); |
208 | | - } |
| 178 | + if (members != null) FlxSound.stopSounds(cast members); |
209 | 179 | } |
210 | 180 |
|
211 | 181 | public override function destroy():Void |
@@ -241,30 +211,19 @@ class SoundGroup extends FlxTypedGroup<FunkinSound> |
241 | 211 | { |
242 | 212 | // account for different offsets per sound? |
243 | 213 |
|
244 | | - var sources:Array<AudioSource> = []; |
| 214 | + var sounds:Array<FlxSound> = []; |
245 | 215 |
|
246 | 216 | forEachAlive(function(sound:FunkinSound) { |
247 | | - if (!sound.loaded || sound.length < time) |
| 217 | + if (!sound.loaded || sound.length < time || !sound.playing) |
248 | 218 | { |
249 | 219 | return; |
250 | 220 | } |
251 | 221 |
|
252 | | - if (sound._pausedByHandler || !sound.source.playing) |
253 | | - { |
254 | | - sound.time = time; |
255 | | - } |
256 | | - else |
257 | | - { |
258 | | - sound.prepare(time); |
259 | | - sources.push(sound.source); |
260 | | - |
261 | | - sound._paused = false; |
262 | | - sound._completed = false; |
263 | | - sound.active = true; |
264 | | - } |
| 222 | + sound.prepare(time); |
| 223 | + sounds.push(sound); |
265 | 224 | }); |
266 | 225 |
|
267 | | - AudioSource.playSources(sources); |
| 226 | + FlxSound.playSounds(sounds); |
268 | 227 |
|
269 | 228 | return time; |
270 | 229 | } |
|
0 commit comments