fix: getFreeTrack() would return a track it just returned when the timing coincides

This commit is contained in:
minjaesong
2024-02-21 21:43:55 +09:00
parent 549c03c2b4
commit f7b0dfb5bb
5 changed files with 9 additions and 15 deletions

View File

@@ -124,7 +124,7 @@ class AudioMixer : Disposable {
*/
fun getFreeTrackNoMatterWhat(): TerrarumAudioMixerTrack {
synchronized(this) {
return getFreeTrack() ?: dynamicTracks.minBy { it.playStartedTime }
return getFreeTrack() ?: dynamicTracks.minBy { it.playStartedTime }.also { it.checkedOutTime = System.nanoTime() }
}
}
@@ -134,7 +134,10 @@ class AudioMixer : Disposable {
fun getFreeTrack(): TerrarumAudioMixerTrack? {
synchronized(this) {
return dynamicTracks.filter { it.trackingTarget == null && !it.isPlaying }
.minByOrNull { it.playStartedTime }
.minByOrNull { maxOf(it.checkedOutTime, it.playStartedTime) }
.also {
it?.checkedOutTime = System.nanoTime()
}
}
}