GlobalScope => CoroutineScope in ABMonitor'DelicateCoroutinesApi' warning.
This commit is contained in:
parent
ff9f32dc83
commit
7a90328900
1 changed files with 10 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue