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
|
package mg.dot.feufaro.midi
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import mg.dot.feufaro.FileRepository
|
import mg.dot.feufaro.FileRepository
|
||||||
|
|
@ -38,6 +43,8 @@ actual class MediaPlayer actual constructor(
|
||||||
private var currentGlobalVolume: Float = 0.8f
|
private var currentGlobalVolume: Float = 0.8f
|
||||||
|
|
||||||
private var currentTempo: Float = 1.0f
|
private var currentTempo: Float = 1.0f
|
||||||
|
private val playerScope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||||
|
private var abJob: Job? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
try {
|
try {
|
||||||
|
|
@ -90,6 +97,7 @@ actual class MediaPlayer actual constructor(
|
||||||
fun release() {
|
fun release() {
|
||||||
sequencer?.close()
|
sequencer?.close()
|
||||||
synthetizer?.close()
|
synthetizer?.close()
|
||||||
|
playerScope.cancel()
|
||||||
}
|
}
|
||||||
actual fun setVolume(level: Float) {
|
actual fun setVolume(level: Float) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -139,7 +147,8 @@ actual class MediaPlayer actual constructor(
|
||||||
pointB = -1L
|
pointB = -1L
|
||||||
}
|
}
|
||||||
private fun startABMonitor() {
|
private fun startABMonitor() {
|
||||||
GlobalScope.launch {
|
abJob?.cancel()
|
||||||
|
abJob = playerScope.launch {
|
||||||
while(isLoopingAB) {
|
while(isLoopingAB) {
|
||||||
val currentTick = sequencer?.tickPosition?: 0L
|
val currentTick = sequencer?.tickPosition?: 0L
|
||||||
if (currentTick >= pointB) {
|
if (currentTick >= pointB) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue