From 7a90328900ffe2fb3f87ef850806d7bc8fdfe93b Mon Sep 17 00:00:00 2001 From: "hasinarak3@gmail.com" Date: Wed, 28 Jan 2026 16:06:53 +0300 Subject: [PATCH] GlobalScope => CoroutineScope in ABMonitor'DelicateCoroutinesApi' warning. --- .../kotlin/mg/dot/feufaro/midi/MidiPlayer.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt index b6625fe..771e54e 100644 --- a/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt +++ b/composeApp/src/desktopMain/kotlin/mg/dot/feufaro/midi/MidiPlayer.kt @@ -1,6 +1,11 @@ package mg.dot.feufaro.midi +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel import kotlinx.coroutines.delay import kotlinx.coroutines.launch import mg.dot.feufaro.FileRepository @@ -38,6 +43,8 @@ actual class MediaPlayer actual constructor( private var currentGlobalVolume: Float = 0.8f private var currentTempo: Float = 1.0f + private val playerScope = CoroutineScope(Dispatchers.Default + SupervisorJob()) + private var abJob: Job? = null init { try { @@ -90,6 +97,7 @@ actual class MediaPlayer actual constructor( fun release() { sequencer?.close() synthetizer?.close() + playerScope.cancel() } actual fun setVolume(level: Float) { try { @@ -139,7 +147,8 @@ actual class MediaPlayer actual constructor( pointB = -1L } private fun startABMonitor() { - GlobalScope.launch { + abJob?.cancel() + abJob = playerScope.launch { while(isLoopingAB) { val currentTick = sequencer?.tickPosition?: 0L if (currentTick >= pointB) {